1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
pub(crate) trait StringExt {
    fn trim_end_inplace(&mut self);
}

impl StringExt for String {
    fn trim_end_inplace(&mut self) {
        self.truncate(self.trim_end().len());
    }
}

#[test]
fn test_trim_end_inplace() {
    let mut s = String::from("test string \n\n");
    s.trim_end_inplace();

    assert_eq!(s, "test string");
}