Trait Sequence

Source
pub trait Sequence {
    type Item;
    type Iter: Iterator<Item = Self::Item>;

    // Required method
    fn into_iter(self) -> Self::Iter;

    // Provided methods
    fn collect_array<const N: usize>(self) -> [Self::Item; N]
       where Self: Sized + ConstMinLen<N> { ... }
    fn map<F, B>(self, f: F) -> Map<Self, F>
       where Self: Sized,
             F: FnMut(Self::Item) -> B { ... }
    fn enumerate(self) -> Enumerate<Self>
       where Self: Sized { ... }
    fn const_take_exact<const N: usize>(self) -> ConstTakeExact<Self, N>
       where Self: Sized + ConstMinLen<N> { ... }
}
Expand description

Represents a stateless abstract sequence of values.

This trait closely resembles Iterator in terms of functionality but unlike the latter, it cannot yield its elements directly. Instead, it must first be irreversibly converted into an iterator using into_iter.

This design allows a Sequence to encode additional invariants, such as a constant size, which is not possible with standard iterators.

Required Associated Types§

Source

type Item

Source

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

Required Methods§

Source

fn into_iter(self) -> Self::Iter

Converts this sequence into a (stateful) iterator.

Provided Methods§

Source

fn collect_array<const N: usize>(self) -> [Self::Item; N]
where Self: Sized + ConstMinLen<N>,

Collects this sequence’s elements into an array.

Source

fn map<F, B>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> B,

Returns a new sequence that transforms every element of the original sequence using f.

Source

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Returns a new sequence that yields the current iteration index together with every element.

Source

fn const_take_exact<const N: usize>(self) -> ConstTakeExact<Self, N>
where Self: Sized + ConstMinLen<N>,

Returns a new sequence that yields exactly N first elements of the original sequence.

Implementors§