/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_on_unimplemented(
- message="a value of type `{Self}` cannot be built from an iterator \
- over elements of type `{A}`",
- label="value of type `{Self}` cannot be built from `std::iter::Iterator<Item={A}>`",
+ message = "a value of type `{Self}` cannot be built from an iterator \
+ over elements of type `{A}`",
+ label = "value of type `{Self}` cannot be built from `std::iter::Iterator<Item={A}>`"
)]
pub trait FromIterator<A>: Sized {
/// Creates a value from an iterator.
/// assert_eq!(v, vec![5, 5, 5, 5, 5]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
- fn from_iter<T: IntoIterator<Item=A>>(iter: T) -> Self;
+ fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self;
}
/// Conversion into an `Iterator`.
/// Which kind of iterator are we turning this into?
#[stable(feature = "rust1", since = "1.0.0")]
- type IntoIter: Iterator<Item=Self::Item>;
+ type IntoIter: Iterator<Item = Self::Item>;
/// Creates an iterator from a value.
///
pub trait Extend<A> {
/// Extends a collection with the contents of an iterator.
///
- /// As this is the only method for this trait, the [trait-level] docs
+ /// As this is the only required method for this trait, the [trait-level] docs
/// contain more details.
///
/// [trait-level]: trait.Extend.html
/// assert_eq!("abcdef", &message);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
- fn extend<T: IntoIterator<Item=A>>(&mut self, iter: T);
+ fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T);
+
+ /// Extends a collection with exactly one element.
+ #[unstable(feature = "extend_one", issue = "none")]
+ fn extend_one(&mut self, item: A) {
+ self.extend(Some(item));
+ }
+
+ /// Reserves capacity in a collection for the given number of additional elements.
+ ///
+ /// The default implementation does nothing.
+ #[unstable(feature = "extend_one", issue = "none")]
+ fn extend_reserve(&mut self, additional: usize) {
+ let _ = additional;
+ }
}
#[stable(feature = "extend_for_unit", since = "1.28.0")]
fn extend<T: IntoIterator<Item = ()>>(&mut self, iter: T) {
iter.into_iter().for_each(drop)
}
+ fn extend_one(&mut self, _item: ()) {}
}