-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Redundant methods in core::str::StrSlice
#15379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
While similarly named, they do have different semantics. The fn main() {
let a = "foo bar baz";
println!("{}", a.split(' ').take(2).collect::<Vec<&str>>());
println!("{}", a.splitn(' ', 2).collect::<Vec<&str>>());
} As in, these are not entirely redundant, but they are indeed unfortunately named. |
I as well was oblivious to the differing behavior of splitn. An example of another difference: fn main() {
let a = "foo bar baz";
for i in a.split(' ').take(1) { println!("{}", i); }
for i in a.splitn(' ', 1) {:println!("{}", i); }
} At the very least, removing rsplitn in favor of |
I don't think so, because I'll close this bug since it was a misunderstanding on my part. |
Did you mean For the string As with split.take/splitn, it's unfortunate to have to have similar names but the semantics do differ slightly :( |
In rust-lang/rfcs#153 in was noticed that
core::str::StrSlice
has some redundant methods:mystr.splitn(n)
acts asmystr.split().take(n)
mystr.rsplitn(n)
acts asmystr.split().rev().take(n)
There isn't any efficiency gain here --- the code in the iterator
CharSplitsN
just replicates that ofiter::Take
anditer::Rev
. So this is pure redundancy and ought to be removed.The text was updated successfully, but these errors were encountered: