Add basic 'shared_from_iter' impls.

This commit is contained in:
Mazdak Farrokhzad 2019-06-19 01:39:51 +02:00
parent 3c805ce183
commit 689c64c469
2 changed files with 14 additions and 0 deletions

View File

@ -1213,6 +1213,13 @@ impl<T> From<Vec<T>> for Rc<[T]> {
}
}
#[stable(feature = "shared_from_iter", since = "1.37.0")]
impl<T> core::iter::FromIterator<T> for Rc<[T]> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
iter.into_iter().collect::<Vec<T>>().into()
}
}
/// `Weak` is a version of [`Rc`] that holds a non-owning reference to the
/// managed value. The value is accessed by calling [`upgrade`] on the `Weak`
/// pointer, which returns an [`Option`]`<`[`Rc`]`<T>>`.

View File

@ -1785,6 +1785,13 @@ impl<T> From<Vec<T>> for Arc<[T]> {
}
}
#[stable(feature = "shared_from_iter", since = "1.37.0")]
impl<T> core::iter::FromIterator<T> for Arc<[T]> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
iter.into_iter().collect::<Vec<T>>().into()
}
}
#[cfg(test)]
mod tests {
use std::boxed::Box;