pub struct Finish<T, E> { /* private fields */ }
Expand description
Finish
is a type that represents a value which
may have an error occurred during the computation.
Logically, Finish<T, E>
is equivalent to Result<T, (T, E)>
.
Implementations§
source§impl<T, E> Finish<T, E>
impl<T, E> Finish<T, E>
sourcepub fn new(value: T, error: Option<E>) -> Self
pub fn new(value: T, error: Option<E>) -> Self
Makes a new instance.
§Examples
use libflate::Finish;
// The result value of a succeeded computation
let succeeded = Finish::new("value", None as Option<()>);
assert_eq!(succeeded.into_result(), Ok("value"));
// The result value of a failed computation
let failed = Finish::new("value", Some("error"));
assert_eq!(failed.into_result(), Err("error"));
sourcepub fn unwrap(self) -> (T, Option<E>)
pub fn unwrap(self) -> (T, Option<E>)
Unwraps the instance.
§Examples
use libflate::Finish;
let succeeded = Finish::new("value", None as Option<()>);
assert_eq!(succeeded.unwrap(), ("value", None));
let failed = Finish::new("value", Some("error"));
assert_eq!(failed.unwrap(), ("value", Some("error")));
sourcepub fn into_result(self) -> Result<T, E>
pub fn into_result(self) -> Result<T, E>
Converts from Finish<T, E>
to Result<T, E>
.
§Examples
use libflate::Finish;
let succeeded = Finish::new("value", None as Option<()>);
assert_eq!(succeeded.into_result(), Ok("value"));
let failed = Finish::new("value", Some("error"));
assert_eq!(failed.into_result(), Err("error"));
sourcepub fn as_result(&self) -> Result<&T, &E>
pub fn as_result(&self) -> Result<&T, &E>
Converts from Finish<T, E>
to Result<&T, &E>
.
§Examples
use libflate::Finish;
let succeeded = Finish::new("value", None as Option<()>);
assert_eq!(succeeded.as_result(), Ok(&"value"));
let failed = Finish::new("value", Some("error"));
assert_eq!(failed.as_result(), Err(&"error"));
Trait Implementations§
source§impl<T: Ord, E: Ord> Ord for Finish<T, E>
impl<T: Ord, E: Ord> Ord for Finish<T, E>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl<T: PartialEq, E: PartialEq> PartialEq for Finish<T, E>
impl<T: PartialEq, E: PartialEq> PartialEq for Finish<T, E>
source§impl<T: PartialOrd, E: PartialOrd> PartialOrd for Finish<T, E>
impl<T: PartialOrd, E: PartialOrd> PartialOrd for Finish<T, E>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<T: Eq, E: Eq> Eq for Finish<T, E>
impl<T, E> StructuralPartialEq for Finish<T, E>
Auto Trait Implementations§
impl<T, E> Freeze for Finish<T, E>
impl<T, E> RefUnwindSafe for Finish<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for Finish<T, E>
impl<T, E> Sync for Finish<T, E>
impl<T, E> Unpin for Finish<T, E>
impl<T, E> UnwindSafe for Finish<T, E>where
T: UnwindSafe,
E: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more