pub struct Finish<T, E> {
value: T,
error: Option<E>,
}
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)>
.
Fields
value: T
error: Option<E>
Implementations
sourceimpl<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
sourceimpl<T: Ord, E: Ord> Ord for Finish<T, E>
impl<T: Ord, E: Ord> Ord for Finish<T, E>
sourceimpl<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>
sourcefn partial_cmp(&self, other: &Finish<T, E>) -> Option<Ordering>
fn partial_cmp(&self, other: &Finish<T, E>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn 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
impl<T: Eq, E: Eq> Eq for Finish<T, E>
impl<T, E> StructuralEq for Finish<T, E>
impl<T, E> StructuralPartialEq for Finish<T, E>
Auto Trait Implementations
impl<T, E> RefUnwindSafe for Finish<T, E> where
E: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, E> Send for Finish<T, E> where
E: Send,
T: Send,
impl<T, E> Sync for Finish<T, E> where
E: Sync,
T: Sync,
impl<T, E> Unpin for Finish<T, E> where
E: Unpin,
T: Unpin,
impl<T, E> UnwindSafe for Finish<T, E> where
E: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more