-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Add Iterator::collect_into #48597
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
Add Iterator::collect_into #48597
Changes from 4 commits
f1eef5c
4b4efcc
e0342c3
873ed10
4a87577
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -267,6 +267,11 @@ impl<I: Iterator> IntoIterator for I { | |
/// or, in the case of collections that permit multiple entries with equal | ||
/// keys, that entry is inserted. | ||
/// | ||
/// When extending with items from [Iterator](trait.Iterator.html), it's often | ||
/// more convenient to use | ||
/// [Iterator::collect_into](trait.Iterator.html#method.collect_into). It works | ||
/// exactly the same way, but is called on series instead of collection. | ||
/// | ||
/// # Examples | ||
/// | ||
/// Basic usage: | ||
|
@@ -352,6 +357,13 @@ pub trait Extend<A> { | |
fn extend<T: IntoIterator<Item=A>>(&mut self, iter: T); | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.26.0")] | ||
impl <'a, A, E: Extend<A>> Extend<A> for &'a mut E { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we really do this? Regardless of crater, RFC 1023 calls There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cuviper yeah I do believe it's a breaking change technically, but if it doesn't actually break anything in practice we may have leeway to land it. |
||
fn extend<T: IntoIterator<Item=A>>(&mut self, iter: T) { | ||
(*self).extend(iter) | ||
} | ||
} | ||
|
||
/// An iterator able to yield elements from both ends. | ||
/// | ||
/// Something that implements `DoubleEndedIterator` has one extra capability | ||
|
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.
Good example.. perhaps include a bit longer example as well which is more real-worldy?