Struct iter_fixed::IteratorFixed[][src]

pub struct IteratorFixed<I: Iterator, const N: usize> { /* fields omitted */ }

Iterator of fixed size

A type that can be usen a bit like an ordinary Iterator but with a compile time guaranteed length. This enables us to turn them back into collections of fixed size without having to perform unnecessary checks during run time.

Just like Iterator, IteratorFixed provides a lot of methods like:

  • map
  • inspect
  • skip
  • step_by
  • chain
  • enumerate
  • take
  • zip
  • rev
  • copied
  • cloned

however it does not support methods like filter or take_while which will affect the length during runtime.

Implementations

impl<I, const N: usize> IteratorFixed<I, N> where
    I: Iterator
[src]

pub unsafe fn from_iter<II: IntoIterator<IntoIter = I>>(i: II) -> Self[src]

Safety

Caller has to guarantee that the given iterator will yield exactly N elements

pub fn map<U, F: FnMut(<I as Iterator>::Item) -> U>(
    self,
    p: F
) -> IteratorFixed<Map<I, F>, N>
[src]

pub fn inspect<F: FnMut(&<I as Iterator>::Item)>(
    self,
    p: F
) -> IteratorFixed<Inspect<I, F>, N>
[src]

pub fn skip<const SKIP: usize>(
    self
) -> IteratorFixed<Skip<I>, { sub_or_zero(N, SKIP) }>
[src]

pub fn step_by<const STEP: usize>(
    self
) -> IteratorFixed<StepBy<I>, { ceiling_div(N, STEP) }>
[src]

pub fn chain<IIF, I2, const M: usize>(
    self,
    other: IIF
) -> IteratorFixed<Chain<I, I2>, { N + M }> where
    IIF: IntoIteratorFixed<I2, M>,
    I2: Iterator<Item = <I as IntoIterator>::Item>, 
[src]

pub fn enumerate(self) -> IteratorFixed<Enumerate<I>, N>[src]

pub fn take<const TAKE: usize>(self) -> IteratorFixed<Take<I>, { min(TAKE, N) }>[src]

pub fn zip<U, IIF, I2>(self, other: IIF) -> IteratorFixed<Zip<I, I2>, N> where
    IIF: IntoIteratorFixed<I2, N>,
    I2: Iterator<Item = U>, 
[src]

pub fn rev(self) -> IteratorFixed<Rev<I>, N> where
    I: DoubleEndedIterator
[src]

pub fn collect<U: FromIteratorFixed<I, N>>(self) -> U[src]

Transforms a fixed size iterator into a collection of compile time known size.

Basic usage:

use iter_fixed::IntoIteratorFixed;

let two_four_six = [1, 2, 3].into_iter_fixed().map(|x| 2 * x);

let a: [i32; 3] = two_four_six.collect();
assert_eq!(a, [2, 4, 6]);

impl<'a, I, T: 'a, const N: usize> IteratorFixed<I, N> where
    I: Iterator<Item = &'a T>, 
[src]

pub fn copied(self) -> IteratorFixed<Copied<I>, N> where
    T: Copy
[src]

pub fn cloned(self) -> IteratorFixed<Cloned<I>, N> where
    T: Clone
[src]

impl<I, I2, const N: usize, const M: usize> IteratorFixed<I, N> where
    I: Iterator<Item = IteratorFixed<I2, M>>,
    I2: Iterator
[src]

Trait Implementations

impl<T, I: Iterator<Item = T>, const N: usize> IntoIterator for IteratorFixed<I, N>[src]

Convert the fixed size iterator into an ordinary core::iter::Iterator allowing it to be used with for loop syntax

type Item = T

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

fn into_iter(self) -> I[src]

Convert the fixed size iterator into an ordinary core::iter::Iterator

impl<I: Iterator, const N: usize> IntoIteratorFixed<I, N> for IteratorFixed<I, N> where
    IteratorFixed<I, N>: IntoIterator
[src]

fn into_iter_fixed(self) -> IteratorFixed<I, N>[src]

IteratorFixed implements IntoIteratorFixed as a no op. This allows passing an IteratorFixed where an IntoIteratorFixed was expected

Basic usage with zip which expects an IntoIteratorFixed as its argument:

use iter_fixed::IntoIteratorFixed;
let one_one = [1, 1].into_iter_fixed();
let zipped: [_; 2] = [1, 2].into_iter_fixed().zip(one_one).collect();

assert_eq!(zipped, [(1, 1), (2, 1)]);

Auto Trait Implementations

impl<I, const N: usize> Send for IteratorFixed<I, N> where
    I: Send

impl<I, const N: usize> Sync for IteratorFixed<I, N> where
    I: Sync

impl<I, const N: usize> Unpin for IteratorFixed<I, N> where
    I: Unpin

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<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.