Struct Iter

Source
pub struct Iter<'a, T> { /* private fields */ }
Expand description

Iterates over all permutations of a slice.

The permutations are iterated in value order:

let mut iter = Iter::new(&mut xs);
let mut i = 0;
while let Some(xs) = iter.next() {
    assert_eq!(encode(xs), i);
    i += 1;
}

If the iteration goes to the end (i.e. next returns None), then the slice is restored to its initial value (i.e. increasing):

let saved_xs = xs.clone();
let mut iter = Iter::new(&mut xs);
while iter.next().is_some() {}
assert_eq!(xs, saved_xs);

§Examples

let mut iter = Iter::new(&mut xs);
while let Some(xs) = iter.next() {
    process(xs);
}

Implementations§

Source§

impl<'a, T: Ord> Iter<'a, T>

Source

pub fn new(xs: &mut [T]) -> Iter<'_, T>

Constructs an iterator with an increasing slice.

§Panics

Panics in debug mode if xs is not increasing.

Source

pub fn next(&mut self) -> Option<&[T]>

Returns the next permutation.

If iteration is over, returns None.

Auto Trait Implementations§

§

impl<'a, T> Freeze for Iter<'a, T>

§

impl<'a, T> RefUnwindSafe for Iter<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for Iter<'a, T>
where T: Send,

§

impl<'a, T> Sync for Iter<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for Iter<'a, T>

§

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

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.