pub enum Resultish<T, E> {
Ok(T),
Err(E),
Both(T, E),
}Variants§
Ok(T)
Contains only a success value
Err(E)
Contains only an error value
Both(T, E)
Contains a success and error value
Implementations§
Source§impl<T, E> Resultish<T, E>
impl<T, E> Resultish<T, E>
Sourcepub fn as_mut(&mut self) -> Resultish<&mut T, &mut E>
pub fn as_mut(&mut self) -> Resultish<&mut T, &mut E>
Converts from &mut Resultish<T, E> to Resultish<&mut T, &mut E>.
Sourcepub fn has_ok(&self) -> bool
pub fn has_ok(&self) -> bool
Returns true if the result contains a success value.
§Examples
use resultish::Resultish::{self, Both, Err, Ok};
let x: Resultish<i32, &str> = Ok(3);
assert_eq!(x.has_ok(), true);
let x: Resultish<i32, &str> = Err("Some error message");
assert_eq!(x.has_ok(), false);
let x: Resultish<i32, &str> = Both(3, "Some error message");
assert_eq!(x.has_ok(), true);Sourcepub fn has_err(&self) -> bool
pub fn has_err(&self) -> bool
Returns true if the result contains an error value.
§Examples
use resultish::Resultish::{self, Both, Err, Ok};
let x: Resultish<i32, &str> = Ok(3);
assert_eq!(x.has_err(), false);
let x: Resultish<i32, &str> = Err("Some error message");
assert_eq!(x.has_err(), true);
let x: Resultish<i32, &str> = Both(3, "Some error message");
assert_eq!(x.has_err(), true);Sourcepub fn lenient(self) -> Result<T, E>
pub fn lenient(self) -> Result<T, E>
Convert to Result leniently: Both is mapped to Result::Ok, and the error value
is discarded.
§Examples
use resultish::Resultish::{self, Both, Err, Ok};
let x: Resultish<i32, &str> = Ok(3);
assert_eq!(x.lenient(), Result::Ok(3));
let x: Resultish<i32, &str> = Err("Some error message");
assert_eq!(x.lenient(), Result::Err("Some error message"));
let x: Resultish<i32, &str> = Both(3, "Some error message");
assert_eq!(x.lenient(), Result::Ok(3));Sourcepub fn lenient_err(self) -> Option<E>
pub fn lenient_err(self) -> Option<E>
Sourcepub fn lenient_ok(self) -> Option<T>
pub fn lenient_ok(self) -> Option<T>
Sourcepub fn map<U, F>(self, op: F) -> Resultish<U, E>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, op: F) -> Resultish<U, E>where
F: FnOnce(T) -> U,
Maps a Resultish<T, E> to Resultish<U, E> by applying a function to the success value,
and leaving the error value untouched.
Sourcepub fn map_err<F, O>(self, op: O) -> Resultish<T, F>where
O: FnOnce(E) -> F,
pub fn map_err<F, O>(self, op: O) -> Resultish<T, F>where
O: FnOnce(E) -> F,
Maps a Resultish<T, E> to Resultish<T, F> by applying a function to the error value,
and leaving the success value untouched.
Sourcepub fn strict(self) -> Result<T, E>
pub fn strict(self) -> Result<T, E>
Convert to Result strictly: Both is mapped to Result::Err, and the success value
is discarded.
§Examples
use resultish::Resultish::{self, Both, Err, Ok};
let x: Resultish<i32, &str> = Ok(3);
assert_eq!(x.strict(), Result::Ok(3));
let x: Resultish<i32, &str> = Err("Some error message");
assert_eq!(x.strict(), Result::Err("Some error message"));
let x: Resultish<i32, &str> = Both(3, "Some error message");
assert_eq!(x.strict(), Result::Err("Some error message"));Sourcepub fn strict_err(self) -> Option<E>
pub fn strict_err(self) -> Option<E>
Sourcepub fn tuple(self) -> (Option<T>, Option<E>)
pub fn tuple(self) -> (Option<T>, Option<E>)
Convert to tuple of the success and error values.
§Examples
use resultish::Resultish::{self, Both, Err, Ok};
let x: Resultish<i32, &str> = Ok(3);
assert_eq!(x.tuple(), (Some(3), None));
let x: Resultish<i32, &str> = Err("Some error message");
assert_eq!(x.tuple(), (None, Some("Some error message")));
let x: Resultish<i32, &str> = Both(3, "Some error message");
assert_eq!(x.tuple(), (Some(3), Some("Some error message")));Trait Implementations§
impl<T: Copy, E: Copy> Copy for Resultish<T, E>
impl<T: Eq, E: Eq> Eq for Resultish<T, E>
Source§impl<T: Ord, E: Ord> Ord for Resultish<T, E>
impl<T: Ord, E: Ord> Ord for Resultish<T, E>
1.21.0 (const: unstable) · 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 Resultish<T, E>
impl<T: PartialEq, E: PartialEq> PartialEq for Resultish<T, E>
Source§impl<T: PartialOrd, E: PartialOrd> PartialOrd for Resultish<T, E>
impl<T: PartialOrd, E: PartialOrd> PartialOrd for Resultish<T, E>
impl<T, E> StructuralPartialEq for Resultish<T, E>
Auto Trait Implementations§
impl<T, E> Freeze for Resultish<T, E>
impl<T, E> RefUnwindSafe for Resultish<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for Resultish<T, E>
impl<T, E> Sync for Resultish<T, E>
impl<T, E> Unpin for Resultish<T, E>
impl<T, E> UnsafeUnpin for Resultish<T, E>where
T: UnsafeUnpin,
E: UnsafeUnpin,
impl<T, E> UnwindSafe for Resultish<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