Open
Description
Consider the following use case:
// A command interpreter with a "print" command, which prints what comes after it
let mut words = line.split_whitespace();
match words.next() {
"print" => {
// How could we get the rest that comes after the command word?
// We could perhaps collect the words, and join them with a space, but that's lossy,
// and doesn't sound very efficient.
let rest;
println!("{}", rest),
}
unk => println!("Unknown command: {}", unk),
}
Some iterators, like str::Chars
already have an as_str
method. The only question is whether it is possible to implement as_str
for the Split API, without making any breaking changes.