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: PartialOrd, E: PartialOrd> PartialOrd for Finish<T, E>
impl<T: PartialOrd, E: PartialOrd> PartialOrd for Finish<T, E>
impl<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