Struct perm::PermIter[][src]

pub struct PermIter<'a, T> where
    T: ExactSizeIterator + Clone,
    T::Item: Clone
{ /* fields omitted */ }

Permutation iterator

Design

Implementation of Iterator works on an external buffer, which you provide in new(). In some first approaches, the iterator made new vector for each call to next(), which was slow. Using a RefCell speeds up about 150%.

Examples

use {
    core::cell::RefCell,
    perm::PermIter,
};


let output_buffer = RefCell::new(Vec::with_capacity(4));
let mut iter = PermIter::new(
    vec![0_u8..=0, 0..=0, 0..=2, 0..=2],
    &output_buffer,
);
for s in &[
    &[0, 0, 0, 0], &[0, 0, 1, 0], &[0, 0, 2, 0],
    &[0, 0, 0, 1], &[0, 0, 1, 1], &[0, 0, 2, 1],
    &[0, 0, 0, 2], &[0, 0, 1, 2], &[0, 0, 2, 2],
] {
    assert_eq!(&*iter.next().unwrap(), s);
}
assert!(iter.next().is_none());

Implementations

impl<'a, T> PermIter<'a, T> where
    T: ExactSizeIterator + Clone,
    T::Item: Clone
[src]

pub fn new(data: Vec<T>, output_buffer: &'a RefCell<Vec<T::Item>>) -> Self[src]

Makes new instance

Output buffer is used for better performance. It will be updated inside each Iterator::next() call. The new content will be returned to you.

Trait Implementations

impl<'a, T: Debug> Debug for PermIter<'a, T> where
    T: ExactSizeIterator + Clone,
    T::Item: Clone,
    T::Item: Debug,
    T::Item: Debug
[src]

impl<T> Eq for PermIter<'_, T> where
    T: ExactSizeIterator + Clone + Eq,
    T::Item: Clone + Eq
[src]

impl<T> Hash for PermIter<'_, T> where
    T: ExactSizeIterator + Clone + Hash,
    T::Item: Clone + Hash
[src]

impl<'a, T> Iterator for PermIter<'a, T> where
    T: ExactSizeIterator + Clone,
    T::Item: Clone
[src]

type Item = Ref<'a, Vec<T::Item>>

The type of the elements being iterated over.

impl<T> PartialEq<PermIter<'_, T>> for PermIter<'_, T> where
    T: ExactSizeIterator + Clone + PartialEq,
    T::Item: Clone + PartialEq
[src]

Auto Trait Implementations

impl<'a, T> !RefUnwindSafe for PermIter<'a, T>

impl<'a, T> !Send for PermIter<'a, T>

impl<'a, T> !Sync for PermIter<'a, T>

impl<'a, T> Unpin for PermIter<'a, T> where
    T: Unpin

impl<'a, T> !UnwindSafe for PermIter<'a, T>

Blanket Implementations

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

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

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

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

impl<T, U> Into<U> for T where
    U: From<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, 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.