Debian Codegraph @

util/rewrite_rules.rs

raw
1 // This file is part of the uutils coreutils package.
2 //
3 // For the full copyright and license information, please view the LICENSE
4 // file that was distributed with this source code.
5
6 //! Rules to update the codebase using `rerast`
7
8 /// Converts try!() to ?
9 fn try_to_question_mark<T, E, X: From<E>>(r: Result<T, E>) -> Result<T, X> {
10 replace!(try!(r) => r?);
11 unreachable!()
12 }
13
14 fn trim_left_to_start(s: &str) {
15 replace!(s.trim_left() => s.trim_start());
16 replace!(s.trim_right() => s.trim_end());
17 }
18
19 fn trim_left_matches_to_start<P: FnMut(char) -> bool>(s: &str, inner: P) {
20 replace!(s.trim_left_matches(inner) => s.trim_start_matches(inner));
21 replace!(s.trim_right_matches(inner) => s.trim_end_matches(inner));
22 }