Skip to content
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

Merged
merged 1 commit into from
Aug 28, 2015

Conversation

withoutboats
Copy link
Contributor

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.

@rust-highfive
Copy link
Collaborator

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.

@alexcrichton
Copy link
Member

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.

@alexcrichton alexcrichton added I-needs-decision Issue: In need of a decision. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Aug 24, 2015
@withoutboats
Copy link
Contributor Author

Does this have to be insta-stable because its an impl of a stable trait for a stable type or for another reason?

@sfackler
Copy link
Member

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);
Copy link
Contributor

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)

Copy link
Contributor Author

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.

@alexcrichton
Copy link
Member

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.

@withoutboats
Copy link
Contributor Author

Adjusted implementation of Extend per @ranma42; should be ready to merge if the crater run is okay.

@withoutboats withoutboats force-pushed the extend_string branch 2 times, most recently from 891c121 to 85b6771 Compare August 27, 2015 07:59
@alexcrichton
Copy link
Member

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> {
Copy link
Member

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.

@withoutboats
Copy link
Contributor Author

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)

@alexcrichton
Copy link
Member

@bors: r+ 8af543a

bors added a commit that referenced this pull request Aug 28, 2015
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.
@bors
Copy link
Contributor

bors commented Aug 28, 2015

⌛ Testing commit 8af543a with merge 20a8412...

@bors bors merged commit 8af543a into rust-lang:master Aug 28, 2015
@bluss bluss added the relnotes Marks issues that should be documented in the release notes of the next release. label Sep 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-needs-decision Issue: In need of a decision. relnotes Marks issues that should be documented in the release notes of the next release. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants