File: rewrite_rules.rs

package info (click to toggle)
rust-coreutils 0.0.30-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,388 kB
  • sloc: sh: 1,088; python: 407; javascript: 72; makefile: 51
file content (17 lines) | stat: -rw-r--r-- 553 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! Rules to update the codebase using `rerast`

/// Converts try!() to ?
fn try_to_question_mark<T, E, X: From<E>>(r: Result<T, E>) -> Result<T, X> {
    replace!(try!(r) => r?);
    unreachable!()
}

fn trim_left_to_start(s: &str) {
    replace!(s.trim_left() => s.trim_start());
    replace!(s.trim_right() => s.trim_end());
}

fn trim_left_matches_to_start<P: FnMut(char) -> bool>(s: &str, inner: P) {
    replace!(s.trim_left_matches(inner) => s.trim_start_matches(inner));
    replace!(s.trim_right_matches(inner) => s.trim_end_matches(inner));
}