-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implemented Extend<String> and FromIterator<String> for String. #27956
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
It's somewhat unfortunate that these impls have to be insta-stable, but I'm ok with these. I'll bring this up during the libs triage meeting to make sure we're all on board though. |
Does this have to be insta-stable because its an impl of a stable trait for a stable type or for another reason? |
The stability checking system doesn't consider the stability of trait implementations that are used at the moment. |
fn extend<I: IntoIterator<Item=String>>(&mut self, iterable: I) { | ||
let iterator = iterable.into_iter(); | ||
let (lower_bound, _) = iterator.size_hint(); | ||
self.reserve(lower_bound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the observation from #27986 apply here, too? (i.e. the strings from the iterator might be empty, hence it is better to keep the code simpler and trust the reallocation strategy)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it does, thanks. I was surprised by that code, but thought "when in Rome". If the libs team approves this PR I'll remove that and rebase.
We discussed this at the libs team meeting today and decided this was ok to merge, but I'm going to run crater beforehand to be super sure that there were no accidental regressions. |
d77facc
to
2dd701c
Compare
Adjusted implementation of Extend per @ranma42; should be ready to merge if the crater run is okay. |
891c121
to
85b6771
Compare
Crater reports zero regressions, so this is good to go on that front. |
} | ||
|
||
#[stable(feature = "extend_string", since = "1.4.0")] | ||
impl FromIterator<String> for String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the travis builds are failing due to a syntax error on this line.
85b6771
to
8af543a
Compare
fixed typo (sorry I didn't catch this in a local test, some issue with jemalloc was blocking compiling liballoc & I just didn't deal with it) |
If you have an `Iterator<Item=String>` (say because those items were generated using `.to_string()` or similarly), borrow semantics do not permit you map that to an `Iterator<&'a str>`. These two implementations close a small gap in the `String` API. At the same time I've also made the names of the parameters to `String`'s `Extend` and `FromIterator` implementations consistent.
If you have an
Iterator<Item=String>
(say because those items were generated using.to_string()
or similarly), borrow semantics do not permit you map that to anIterator<&'a str>
. These two implementations close a small gap in theString
API.At the same time I've also made the names of the parameters to
String
'sExtend
andFromIterator
implementations consistent.