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;
// Provided method
fn repeat(value: T) -> Self::Sequence
where T: Clone { ... }
}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§
Sourcetype Length: ArrayLength
type Length: ArrayLength
GenericArray associated length
Sourcetype Sequence: GenericSequence<T, Length = Self::Length> + FromIterator<T>
type Sequence: GenericSequence<T, Length = Self::Length> + FromIterator<T>
Owned sequence type used in conjunction with reference implementations of GenericSequence
Required Methods§
Provided Methods§
Sourcefn repeat(value: T) -> Self::Sequencewhere
T: Clone,
fn repeat(value: T) -> Self::Sequencewhere
T: Clone,
Initializes a new sequence instance by repeating the given value.
Clones the value for all but the last element, taking ownership of the original value for the last.
This is semantically equivalent to FromIterator::from_iter(core::iter::repeat_n(value, N::USIZE))
but available on older Rust versions. repeat_n was stabilized in Rust 1.82.0
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 Swhere
&'a S: IntoIterator,
impl<'a, T: 'a, S: GenericSequence<T>> GenericSequence<T> for &'a Swhere
&'a S: IntoIterator,
Source§impl<'a, T: 'a, S: GenericSequence<T>> GenericSequence<T> for &'a mut Swhere
&'a mut S: IntoIterator,
impl<'a, T: 'a, S: GenericSequence<T>> GenericSequence<T> for &'a mut Swhere
&'a mut S: IntoIterator,
Source§impl<T, N: ArrayLength> GenericSequence<T> for Box<GenericArray<T, N>>
Available on crate feature alloc only.
impl<T, N: ArrayLength> GenericSequence<T> for Box<GenericArray<T, N>>
alloc only.