Enum std::result::Result
pub enum Result<T, E> { Ok(T), Err(E), }
Result
is a type that represents either success (Ok
) or failure (Err
).
Variants
Ok | Contains the success value |
Err | Contains the error value |
Methods
impl<T, E> Result<T, E>
fn is_ok(&self) -> bool
Returns true if the result is Ok
fn is_err(&self) -> bool
Returns true if the result is Err
fn ok(self) -> Option<T>
Convert from Result<T, E>
to Option<T>
fn err(self) -> Option<E>
Convert from Result<T, E>
to Option<E>
fn as_ref<'r>(&'r self) -> Result<&'r T, &'r E>
Convert from Result<T, E>
to Result<&T, &E>
fn as_mut<'r>(&'r mut self) -> Result<&'r mut T, &'r mut E>
Convert from Result<T, E>
to Result<&mut T, &mut E>
fn map<U>(self, op: |T| -> U) -> Result<U, E>
Maps a Result<T, E>
to Result<U, E>
by applying a function to an
contained Ok
value, leaving an Err
value untouched.
This function can be used to compose the results of two functions.
Example:
let res = read_file(file).map(|buf| { parse_bytes(buf) })
fn map_err<F>(self, op: |E| -> F) -> Result<T, F>
Maps a Result<T, E>
to Result<T, F>
by applying a function to an
contained Err
value, leaving an Ok
value untouched.
This function can be used to pass through a successful result while handling an error.
fn and<U>(self, res: Result<U, E>) -> Result<U, E>
Returns res
if the result is Ok
, otherwise returns the Err
value of self
.
fn and_then<U>(self, op: |T| -> Result<U, E>) -> Result<U, E>
Calls op
if the result is Ok
, otherwise returns the Err
value of self
.
This function can be used for control flow based on result values
fn or(self, res: Result<T, E>) -> Result<T, E>
Returns res
if the result is Err
, otherwise returns the Ok
value of self
.
fn or_else<F>(self, op: |E| -> Result<T, F>) -> Result<T, F>
Calls op
if the result is Err
, otherwise returns the Ok
value of self
.
This function can be used for control flow based on result values
fn unwrap(self) -> T
Unwraps a result, yielding the content of an Ok
.
Fails if the value is an Err
.
fn unwrap_err(self) -> E
Unwraps a result, yielding the content of an Err
.
Fails if the value is an Ok
.
Trait Implementations
Derived Implementations
impl<T: Show, E: Show> Show for Result<T, E>
impl<T: TotalOrd, E: TotalOrd> TotalOrd for Result<T, E>
impl<T: TotalEq, E: TotalEq> TotalEq for Result<T, E>
fn assert_receiver_is_total_eq(&self)
impl<T: Ord, E: Ord> Ord for Result<T, E>
fn lt(&self, __arg_0: &Result<T, E>) -> bool
fn le(&self, __arg_0: &Result<T, E>) -> bool
fn gt(&self, __arg_0: &Result<T, E>) -> bool
fn ge(&self, __arg_0: &Result<T, E>) -> bool
impl<T: Eq, E: Eq> Eq for Result<T, E>
impl<T: Clone, E: Clone> Clone for Result<T, E>
fn clone(&self) -> Result<T, E>
Returns a copy of the value. The contents of owned pointers are copied to maintain uniqueness, while the contents of managed pointers are not copied.
fn clone_from(&mut self, source: &Self)
Perform copy-assignment from source
.
a.clone_from(&b)
is equivalent to a = b.clone()
in functionality,
but can be overridden to reuse the resources of a
to avoid unnecessary
allocations.