str::trim_left_matches¶
Level: reference · for working programmers
Deprecated since Rust 1.33 — use
str::trim_start_matchesinstead. The page is here because the name is still in code written before it moved, and it still compiles; a new call site should not use it.
One line: The pre-1.33 name for trim_start_matches.
Same rename, same reason. Behaviour is unchanged: the pattern is removed from the front repeatedly.
Example¶
str_trim_left_matches.rs in full — pasted here by tools/run_examples.py from the file CI compiles and runs.
#![allow(deprecated)]
fn main() {
let s = "xxxvalue";
println!("{:?}", s.trim_left_matches('x'));
println!("{:?}", s.trim_start_matches('x'));
println!("identical: {}", s.trim_left_matches('x') == s.trim_start_matches('x'));
}
Verified output of str_trim_left_matches.rs — regenerated by tools/run_examples.py, never hand-typed.
See also¶
str::trim_start_matches— the method to usestr::strip_prefix— one occurrence, reportedstr::trim_right_matches— the other deprecated name
str::trim_left_matches in the standard library ↗
Po polsku¶
Ta sama zamiana co przy trim_left — left na start — ale przy tej metodzie warto zadać jeszcze drugie pytanie, którego sama poprawka nazwy nie rozstrzyga: czy naprawdę chodziło o usuwanie wzorca wielokrotnie? trim_left_matches('x') na "xxxvalue" zdejmuje wszystkie trzy x, a strip_prefix('x') zdjęłoby jedno i jeszcze powiedziałoby, czy było co zdejmować — stare wywołanie bardzo często pochodzi po prostu z czasów, gdy strip_prefix (stabilne dopiero od 1.45) jeszcze nie istniało, więc przy okazji migracji sprawdź, które zachowanie było zamierzone.
Szukaj po polsku: przestarzała nazwa metody · usuwanie przedrostka raz czy wielokrotnie · rust trim_left_matches deprecated · rust trim_start_matches vs strip_prefix