Trait core::ops::FromResidual

source ·
pub trait FromResidual<R = <Self as Try>::Residual> {
    // Required method
    fn from_residual(residual: R) -> Self;
}
🔬This is a nightly-only experimental API. (try_trait_v2 #84277)
Expand description

用于指定哪些残差可以转换为哪些 crate::ops::Try 类型。

每个 Try 类型都需要从它自己关联的 Residual 类型重新创建,但也可以有额外的 FromResidual 实现来支持与其他 Try 类型的相互转换。

Required Methods§

source

fn from_residual(residual: R) -> Self

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

从兼容的 Residual 类型构造类型。

这应该与 branch 方法一致地实现,以便应用 ? 运算符将返回等效的残差: FromResidual::from_residual(r).branch() --> ControlFlow::Break(r)

(当涉及相互转换时,它不能是相同的残差。)

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),
);
Run

Implementors§

source§

impl<B, C> FromResidual<<ControlFlow<B, C> as Try>::Residual> for ControlFlow<B, C>

source§

impl<T> FromResidual<<Option<T> as Try>::Residual> for Option<T>

source§

impl<T> FromResidual<Yeet<()>> for Option<T>

source§

impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F>

source§

impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Poll<Option<Result<T, F>>>

source§

impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Poll<Result<T, F>>

source§

impl<T, E, F: From<E>> FromResidual<Yeet<E>> for Result<T, F>