str::lines_any¶
Level: reference · for working programmers
Deprecated — use
str::linesinstead. The page is here because the name is still in older code, and it still compiles; a new call site should not use it.
One line: The 1.0-era name for lines, kept compiling and deprecated since Rust 1.4.
Stable since 1.0.0.
lines() originally split only on \n, and lines_any() was the one that also understood \r\n. In Rust 1.4 lines() gained that behaviour, which left the two identical and the longer name pointless.
There is nothing to migrate: delete the _any.
Example¶
str_lines_any.rs in full — pasted here by tools/run_examples.py from the file CI compiles and runs.
#![allow(deprecated)]
fn main() {
let text = "alpha\r\nbeta\ngamma\n";
println!("{:?}", text.lines().collect::<Vec<&str>>());
println!("{:?}", text.lines_any().collect::<Vec<&str>>());
println!("identical: {}", text.lines().eq(text.lines_any()));
}
Verified output of str_lines_any.rs — regenerated by tools/run_examples.py, never hand-typed.
See also¶
str::lines— the method to use- RFC 1212 — how
lines()learned about\r\n— the 2015 proposal that deprecated this name
str::lines_any in the standard library ↗
Po polsku¶
lines_any to nie osobna metoda, tylko nazwa historyczna: do Rusta 1.4 lines() dzielił tekst wyłącznie po \n, a \r\n rozumiał dopiero lines_any(). Od 1.4 obie robią dokładnie to samo, więc cała migracja polega na skasowaniu _any — nie ma tu czego przepisywać. Przy okazji dobrze zapamiętać, co w Ruscie znaczy „przestarzała" (deprecated): metoda nadal się kompiluje i nie zniknie, bo zabrania tego gwarancja stabilności biblioteki standardowej — dostajesz jedynie ostrzeżenie use of deprecated method, wyciszone w przykładzie powyżej atrybutem #![allow(deprecated)]. Jeśli trafiłeś tutaj ze starszego polskiego poradnika, który radzi lines_any() do plików z Windows, to rada nieaktualna od 2015 roku.
Szukaj po polsku: metoda przestarzała · gwarancja stabilności Rusta · rust deprecated method warning · rust lines_any vs lines