generic_array::sequence

Trait GenericSequence

Source
pub unsafe trait GenericSequence<T>: Sized + IntoIterator {
    type Length: ArrayLength;
    type Sequence: GenericSequence<T, Length = Self::Length> + FromIterator<T>;

    // Required method
    fn generate<F>(f: F) -> Self::Sequence
       where F: FnMut(usize) -> T;
}
Expand description

Defines some sequence with an associated length and iteration capabilities.

This is useful for passing N-length generic arrays as generics.

§Safety

Care must be taken when implementing such that methods are safe.

Lengths must match, and element drop on panic must be handled.

Required Associated Types§

Source

type Length: ArrayLength

GenericArray associated length

Source

type Sequence: GenericSequence<T, Length = Self::Length> + FromIterator<T>

Owned sequence type used in conjunction with reference implementations of GenericSequence

Required Methods§

Source

fn generate<F>(f: F) -> Self::Sequence
where F: FnMut(usize) -> T,

Initializes a new sequence instance using the given function.

If the generator function panics while initializing the sequence, any already initialized elements will be dropped.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, T: 'a, S: GenericSequence<T>> GenericSequence<T> for &'a S

Source§

type Length = <S as GenericSequence<T>>::Length

Source§

type Sequence = <S as GenericSequence<T>>::Sequence

Source§

fn generate<F>(f: F) -> Self::Sequence
where F: FnMut(usize) -> T,

Source§

impl<'a, T: 'a, S: GenericSequence<T>> GenericSequence<T> for &'a mut S

Source§

type Length = <S as GenericSequence<T>>::Length

Source§

type Sequence = <S as GenericSequence<T>>::Sequence

Source§

fn generate<F>(f: F) -> Self::Sequence
where F: FnMut(usize) -> T,

Source§

impl<T, N: ArrayLength> GenericSequence<T> for Box<GenericArray<T, N>>

Available on crate feature alloc only.
Source§

type Length = N

Source§

type Sequence = Box<GenericArray<T, N>>

Source§

fn generate<F>(f: F) -> Self::Sequence
where F: FnMut(usize) -> T,

Implementors§

Source§

impl<T, N: ArrayLength> GenericSequence<T> for GenericArray<T, N>
where Self: IntoIterator<Item = T>,