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