Trait sp_std::ops::FromResidual
source · [−]pub trait FromResidual<R = <Self as Try>::Residual> {
fn from_residual(residual: R) -> Self;
}
🔬 This is a nightly-only experimental API. (
try_trait_v2
)Expand description
Used to specify which residuals can be converted into which crate::ops::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
fn from_residual(residual: R) -> Self
🔬 This is a nightly-only experimental API. (
try_trait_v2
)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 must not be an identical residual when interconversion is involved.)
Examples
#![feature(try_trait_v2)]
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),
);
Implementations on Foreign Types
const: unstable · sourceimpl<T> FromResidual<<Option<T> as Try>::Residual> for Option<T>
impl<T> FromResidual<<Option<T> as Try>::Residual> for Option<T>
const: unstable · sourcepub fn from_residual(residual: Option<Infallible>) -> Option<T>
pub fn from_residual(residual: Option<Infallible>) -> Option<T>
🔬 This is a nightly-only experimental API. (
try_trait_v2
)sourceimpl<T, E, F> FromResidual<Result<Infallible, E>> for Poll<Option<Result<T, F>>> where
F: From<E>,
impl<T, E, F> FromResidual<Result<Infallible, E>> for Poll<Option<Result<T, F>>> where
F: From<E>,
sourcepub fn from_residual(x: Result<Infallible, E>) -> Poll<Option<Result<T, F>>>
pub fn from_residual(x: Result<Infallible, E>) -> Poll<Option<Result<T, F>>>
🔬 This is a nightly-only experimental API. (
try_trait_v2
)sourceimpl<T> FromResidual<<Ready<T> as Try>::Residual> for Ready<T>
impl<T> FromResidual<<Ready<T> as Try>::Residual> for Ready<T>
sourcepub fn from_residual(residual: Ready<Infallible>) -> Ready<T>
pub fn from_residual(residual: Ready<Infallible>) -> Ready<T>
🔬 This is a nightly-only experimental API. (
try_trait_v2
)sourceimpl<T> FromResidual<Ready<Infallible>> for Poll<T>
impl<T> FromResidual<Ready<Infallible>> for Poll<T>
sourcepub fn from_residual(residual: Ready<Infallible>) -> Poll<T>
pub fn from_residual(residual: Ready<Infallible>) -> Poll<T>
🔬 This is a nightly-only experimental API. (
try_trait_v2
)sourceimpl<T, E, F> FromResidual<Result<Infallible, E>> for Poll<Result<T, F>> where
F: From<E>,
impl<T, E, F> FromResidual<Result<Infallible, E>> for Poll<Result<T, F>> where
F: From<E>,
sourcepub fn from_residual(x: Result<Infallible, E>) -> Poll<Result<T, F>>
pub fn from_residual(x: Result<Infallible, E>) -> Poll<Result<T, F>>
🔬 This is a nightly-only experimental API. (
try_trait_v2
)