Skip to main content

FallibleGenericSequence

Trait FallibleGenericSequence 

Source
pub unsafe trait FallibleGenericSequence<T>: GenericSequence<T, Sequence: FromFallibleIterator<T>> {
    type Error;

    // Required method
    fn try_generate<F, E>(
        f: F,
    ) -> Result<Result<Self::Sequence, E>, Self::Error>
       where F: FnMut(usize) -> Result<T, E>;
}
Expand description

Extension to GenericSequence for fallible initialization.

§Safety

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

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

§Compatibility

Associated type bounds were only introduced in Rust 1.79, and to ensure easy usage on newer versions of Rust this trait uses that. However, on pre-1.79 Rust, the Sequence: FromFallibleIterator<T> trait is not implied, and must be manually specified when FallibleGenericSequence is used.

Required Associated Types§

Source

type Error

Error type for sequence creation failures, independent of the element generator.

For infallible sequence types such as GenericArray, this is Infallible.

Required Methods§

Source

fn try_generate<F, E>(f: F) -> Result<Result<Self::Sequence, E>, Self::Error>
where F: FnMut(usize) -> Result<T, E>,

Initializes a new sequence instance using the given fallible function.

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

Returns Ok(Ok(sequence)) on success, Ok(Err(e)) if the generator fails, or Err(Self::Error) if the sequence itself cannot be created (e.g., allocation failure).

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: FallibleGenericSequence<T>> FallibleGenericSequence<T> for &'a S

Source§

type Error = <S as FallibleGenericSequence<T>>::Error

Source§

fn try_generate<F, E>(f: F) -> Result<Result<Self::Sequence, E>, Self::Error>
where F: FnMut(usize) -> Result<T, E>,

Source§

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

Source§

type Error = <S as FallibleGenericSequence<T>>::Error

Source§

fn try_generate<F, E>(f: F) -> Result<Result<Self::Sequence, E>, Self::Error>
where F: FnMut(usize) -> Result<T, E>,

Source§

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

Available on crate feature alloc only.
Source§

type Error = AllocError

Source§

fn try_generate<F, E>(f: F) -> Result<Result<Self::Sequence, E>, AllocError>
where F: FnMut(usize) -> Result<T, E>,

Implementors§