# Trait core::ops::FromResidual
[−][src]

    pub trait FromResidual<R = Self::Residual> {
        fn from_residual(residual: R) -> Self;
    }

🔬 This is a nightly-only experimental API. (`try_trait_v2` #84277)

Used to specify which residuals can be converted into which `Try` types.

Every `Try` type needs to be recreatable from its own associated `Residual` type, but can also have additional `FromResidual` implementations to support interconversion with other `Try` types.

## Required methods

### `fn from_residual(residual: R) -> Self`[src]

🔬 This is a nightly-only experimental API. (`try_trait_v2` #84277)

Constructs the type from a compatible `Residual` type.

This should be implemented consistently with the `branch` method such that applying the `?` operator will get back an equivalent residual: `FromResidual::from_residual(r).branch() --> ControlFlow::Break(r)`. (It may not be an identical residual when interconversion is involved.)

# Examples

    #![feature(try_trait_v2)]
    #![feature(control_flow_enum)]
    use std::ops::{ControlFlow, FromResidual};

    assert_eq!(Result::<String, i64>::from_residual(Err(3_u8)), Err(3));
    assert_eq!(Option::<String>::from_residual(None), None);
    assert_eq!(
        ControlFlow::<_, String>::from_residual(ControlFlow::Break(5)),
        ControlFlow::Break(5),
    );

Run
Loading content...

## Implementors

### `impl<B, C> FromResidual<<ControlFlow<B, C> as Try>::Residual> for ControlFlow<B, C>`[src]

#### `fn from_residual(residual: ControlFlow<B, Infallible>) -> Self`[src]

🔬 This is a nightly-only experimental API. (`try_trait_v2` #84277)

### `impl<T> FromResidual<<Option<T> as Try>::Residual> for Option<T>`[src]

#### `fn from_residual(residual: Option<Infallible>) -> Self`[src]

🔬 This is a nightly-only experimental API. (`try_trait_v2` #84277)

### `impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F>`[src]

#### `fn from_residual(residual: Result<Infallible, E>) -> Self`[src]

🔬 This is a nightly-only experimental API. (`try_trait_v2` #84277)

### `impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Poll<Option<Result<T, F>>>`[src]

#### `fn from_residual(x: Result<Infallible, E>) -> Self`[src]

🔬 This is a nightly-only experimental API. (`try_trait_v2` #84277)

### `impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Poll<Result<T, F>>`[src]

#### `fn from_residual(x: Result<Infallible, E>) -> Self`[src]

🔬 This is a nightly-only experimental API. (`try_trait_v2` #84277)
Loading content...