Logo

Programming-Idioms

History of Idiom 151 > diff from v19 to v20

Edit summary for version 20 by programming-idioms.org:
[Rust] +DemoURL

Version 19

2021-03-26, 17:40:55

Version 20

2021-03-26, 17:46:14

Idiom #151 Remove string trailing path separator

Remove last character from string p, if this character is the file path separator of current platform.

Note that this also transforms unix root path "/" into the empty string!

Idiom #151 Remove string trailing path separator

Remove last character from string p, if this character is the file path separator of current platform.

Note that this also transforms unix root path "/" into the empty string!

Variables
p
Variables
p
Extra Keywords
trim
Extra Keywords
trim
Code
let p = if ::std::path::is_separator(p.chars().last().unwrap()) {
    &p[0..p.len()-1]
} else {
    p
};
Code
let p = if ::std::path::is_separator(p.chars().last().unwrap()) {
    &p[0..p.len()-1]
} else {
    p
};
Doc URL
https://doc.rust-lang.org/stable/std/path/fn.is_separator.html
Doc URL
https://doc.rust-lang.org/stable/std/path/fn.is_separator.html
Demo URL
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9c29cd2693a35106c1553cd87ac3ef80