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

pub trait FromResidual<R = <Self as Try>::Residual> {
    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

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

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

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

(当涉及到相互转换时,它可能不是一个相同的 residual。)

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

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