[][src]Struct core_extensions::iterators::IterCloner

pub struct IterCloner<'a, I: 'a> {
    pub iter: &'a I,
}

Constructs an Iterator by cloning the one it references,if the Iterator is Clone.

Constructs an Iterator inside IntoIterator::into_iter by cloning the one it references.

To construct this from an iterator value use this macro ,

Closures can be Copy and/or Clone since Rust 1.26 ,this affects iterators since most iterator methods take closures.

Example

This example only runs from Rust 1.26 onwards,

use core_extensions::iterators::IterCloner;

let list=vec!["hello","awesome","world"];
let iter=list.iter().map(|v|v.len()).filter(|&v| v<6 );
{
    let iter_clone=IterCloner::new(&iter);
    
    for _ in 0..2{
        assert_eq!(iter_clone.into_iter().collect::<Vec<_>>(),vec![5,5]);
    }
}
assert_eq!(iter.into_iter().collect::<Vec<_>>(),vec![5,5]);

Fields

iter: &'a I

The iterator being cloned.

Methods

impl<'a, I: 'a> IterCloner<'a, I> where
    I: Iterator + Clone
[src]

pub fn new(iter: &'a I) -> Self[src]

Constructs an IterCloner.

Trait Implementations

impl<'a, I: 'a> IntoIterator for IterCloner<'a, I> where
    I: Iterator + Clone
[src]

type Item = I::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<'a, I> Clone for IterCloner<'a, I>[src]

impl<'a, I> Copy for IterCloner<'a, I>[src]

Auto Trait Implementations

impl<'a, I> Send for IterCloner<'a, I> where
    I: Sync

impl<'a, I> Sync for IterCloner<'a, I> where
    I: Sync

impl<'a, I> Unpin for IterCloner<'a, I>

impl<'a, I> UnwindSafe for IterCloner<'a, I> where
    I: RefUnwindSafe

impl<'a, I> RefUnwindSafe for IterCloner<'a, I> where
    I: RefUnwindSafe

Blanket Implementations

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The error type returned when the conversion fails.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]