IntoIteratorFixed

Trait IntoIteratorFixed 

Source
pub unsafe trait IntoIteratorFixed<const N: usize> {
    type Item;
    type IntoIter: Iterator<Item = Self::Item>;

    // Required method
    fn into_iter_fixed(self) -> IteratorFixed<Self::IntoIter, N>;
}
Expand description

Conversion into an IteratorFixed.

By implementing IntoIteratorFixed for a type, you define how it will be converted to an iterator of fixed size.

See also: crate::FromIteratorFixed.

§Safety

Implementer has to guarantee that the inner iterator will always yield exactly N elements

Required Associated Types§

Source

type Item

The type of the elements being iterated over.

Source

type IntoIter: Iterator<Item = Self::Item>

What will be the underlaying iterator for the IteratorFixed that we are turning this into?

Required Methods§

Source

fn into_iter_fixed(self) -> IteratorFixed<Self::IntoIter, N>

Creates a fixed size iterator from a value.

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]);

Implementations on Foreign Types§

Source§

impl<'a, T, const N: usize> IntoIteratorFixed<N> for &'a [T; N]

Source§

fn into_iter_fixed(self) -> IteratorFixed<Self::IntoIter, N>

Creates a fixed size iterator from a borrowed array.

Basic usage:

use iter_fixed::IntoIteratorFixed;
fn double<const N: usize>(array: &[i32; N]) -> [i32; N] {
    let two_four_six = array.into_iter_fixed().map(|&x| 2 * x);

    two_four_six.collect()
}
assert_eq!(double(&[1, 2, 3]), [2, 4, 6]);
Source§

type Item = &'a T

Source§

type IntoIter = Iter<'a, T>

Source§

impl<'a, T, const N: usize> IntoIteratorFixed<N> for &'a mut [T; N]

Source§

fn into_iter_fixed(self) -> IteratorFixed<Self::IntoIter, N>

Creates a fixed size iterator from a mutably borrowed array.

Basic usage:

use iter_fixed::IntoIteratorFixed;

// Update `array` in place to element wise x * 2
// return the initial value of the array
fn double<const N: usize>(array: &mut [i32; N]) -> [i32; N] {
    let fixed_iter = array.into_iter_fixed().map(|x| {
        let old = *x;
        *x = 2 * *x;
        old
    });
    fixed_iter.collect()
}
let mut a = [1, 2, 3];
assert_eq!(double(&mut a), [1, 2, 3]);
assert_eq!(a, [2, 4, 6]);
Source§

type Item = &'a mut T

Source§

type IntoIter = IterMut<'a, T>

Source§

impl<T, const N: usize> IntoIteratorFixed<N> for [T; N]

Source§

fn into_iter_fixed(self) -> IteratorFixed<IntoIter<T, N>, N>

Creates a fixed size iterator from an array.

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]);
Source§

type Item = T

Source§

type IntoIter = IntoIter<T, N>

Source§

impl<T: Clone, const N: usize> IntoIteratorFixed<N> for Repeat<T>

Source§

fn into_iter_fixed(self) -> IteratorFixed<Take<Self>, N>

Creates a fixed size iterator from an core::iter::Repeat

Basic usage:

use core::iter;
use iter_fixed::IntoIteratorFixed;

let one_one_one = iter::repeat(1).into_iter_fixed();

let a: [i32; 3] = one_one_one.collect();
assert_eq!(a, [1, 1, 1]);
Source§

type Item = T

Source§

type IntoIter = Take<Repeat<T>>

Implementors§

Source§

impl<I: Iterator, const N: usize> IntoIteratorFixed<N> for IteratorFixed<I, N>
where Self: IntoIterator,