Trait TryExtract

Source
pub trait TryExtract<'a> {
    type Ok;
    type Err;

    // Required method
    fn try_extract(self) -> Result<Self::Ok, Self::Err>;
}
Available on crate feature try only.
Expand description

A trait for uniformly extracting success/error values from various container types.

This provides a generic interface to convert different outcome-carrying types into a standard Result form, enabling unified error handling across:

The conversion preserves semantic meanings:

  • Success cases map to Ok
  • Termination/error cases map to Err

Required Associated Types§

Source

type Ok

The type of success values (may be a reference)

Source

type Err

The type of error values (may be a reference)

Required Methods§

Source

fn try_extract(self) -> Result<Self::Ok, Self::Err>

Converts the container into a Result, preserving semantic meaning

For reference implementations (&Result, &Option, &ControlFlow), this returns references to contained values rather than moving them

Implementations on Foreign Types§

Source§

impl<'a, C, B> TryExtract<'a> for &'a ControlFlow<B, C>

Source§

fn try_extract(self) -> Result<Self::Ok, Self::Err>

Extracts references from ControlFlow:

  • Continue(c) => Ok(&c)
  • Break(b) => Err(&b)
Source§

type Ok = &'a C

Source§

type Err = &'a B

Source§

impl<'a, T> TryExtract<'a> for &'a Option<T>

Source§

fn try_extract(self) -> Result<Self::Ok, Self::Err>

Extracts reference to the contained value if exists

  • &Option:
    • Some(value) => Ok(&value)
    • None => Err(())
Source§

type Ok = &'a T

Source§

type Err = ()

Source§

impl<'a, T, E> TryExtract<'a> for &'a Result<T, E>

Source§

fn try_extract(self) -> Result<Self::Ok, Self::Err>

Extracts references to the contained value:

  • &Result<Ok, Err> => Result<&Ok, &Err>
Source§

type Ok = &'a T

Source§

type Err = &'a E

Source§

impl<'a, T, E> TryExtract<'a> for Result<T, E>

Source§

fn try_extract( self, ) -> Result<<Result<T, E> as TryExtract<'a>>::Ok, <Result<T, E> as TryExtract<'a>>::Err>

Directly returns the owned Result (identity conversion)

Source§

type Ok = T

Source§

type Err = E

Source§

impl<C, B> TryExtract<'_> for ControlFlow<B, C>

Source§

fn try_extract(self) -> Result<Self::Ok, Self::Err>

Converts ControlFlow into Result:

  • Continue(c) => Ok(c)
  • Break(b) => Err(b)
Source§

type Ok = C

Source§

type Err = B

Source§

impl<T> TryExtract<'_> for Option<T>

Source§

fn try_extract(self) -> Result<Self::Ok, Self::Err>

Converts an Option into a Result:

  • Some(value) => Ok(value)
  • None => Err(())

This consumes the Option and moves the contained value

Source§

type Ok = T

Source§

type Err = ()

Implementors§