std::ops::Try - Rust (original) (raw)
Trait std::ops::Try [−] [src]
pub trait Try { type Ok; type Error; fn into_result(self) -> Result<Self::Ok, Self::Error>; fn from_error(v: Self::Error) -> Self; fn from_ok(v: Self::Ok) -> Self; }
🔬 This is a nightly-only experimental API. (try_trait
#42327)
A trait for customizing the behavior of the ?
operator.
A type implementing Try
is one that has a canonical way to view it in terms of a success/failure dichotomy. This trait allows both extracting those success or failure values from an existing instance and creating a new instance from a success or failure value.
type [Ok](#associatedtype.Ok)
🔬 This is a nightly-only experimental API. (try_trait
#42327)
The type of this value when viewed as successful.
type [Error](#associatedtype.Error)
🔬 This is a nightly-only experimental API. (try_trait
#42327)
The type of this value when viewed as failed.
fn [into_result](#tymethod.into%5Fresult)(self) -> [Result](../../std/result/enum.Result.html "enum std::result::Result")<Self::[Ok](../../std/ops/trait.Try.html#associatedtype.Ok "type std::ops::Try::Ok"), Self::[Error](../../std/ops/trait.Try.html#associatedtype.Error "type std::ops::Try::Error")>
🔬 This is a nightly-only experimental API. (try_trait
#42327)
Applies the "?" operator. A return of Ok(t)
means that the execution should continue normally, and the result of ?
is the value t
. A return of Err(e)
means that execution should branch to the innermost enclosing catch
, or return from the function.
If an Err(e)
result is returned, the value e
will be "wrapped" in the return type of the enclosing scope (which must itself implementTry
). Specifically, the value X::from_error(From::from(e))
is returned, where X
is the return type of the enclosing function.
fn [from_error](#tymethod.from%5Ferror)(v: Self::[Error](../../std/ops/trait.Try.html#associatedtype.Error "type std::ops::Try::Error")) -> Self
🔬 This is a nightly-only experimental API. (try_trait
#42327)
Wrap an error value to construct the composite result. For example,Result::Err(x)
and Result::from_error(x)
are equivalent.
fn [from_ok](#tymethod.from%5Fok)(v: Self::[Ok](../../std/ops/trait.Try.html#associatedtype.Ok "type std::ops::Try::Ok")) -> Self
🔬 This is a nightly-only experimental API. (try_trait
#42327)
Wrap an OK value to construct the composite result. For example,Result::Ok(x)
and Result::from_ok(x)
are equivalent.
impl<T, E> Try for [Result](../../std/result/enum.Result.html "enum std::result::Result")<T, E> type [Ok](#associatedtype.Ok) = T; type [Error](#associatedtype.Error) = E;
impl<T> Try for [Option](../../std/option/enum.Option.html "enum std::option::Option")<T> type [Ok](#associatedtype.Ok) = T; type [Error](#associatedtype.Error) = [NoneError](../../std/option/struct.NoneError.html "struct std::option::NoneError");