Enum outcome::prelude::Aberration
source · [−]pub enum Aberration<M, F> {
Mistake(M),
Failure(F),
}
Expand description
Aberration
is a type that can represent a Mistake
, or Failure
.
NOTE: This type will become a alias once !
is stabilized.
See the module documentation for details.
Variants
Mistake(M)
Contains the mistake value. Analogous to
Outcome::Mistake
Failure(F)
Contains the failure value. Analogous to
Outcome::Failure
Implementations
sourceimpl<M, F> Aberration<M, F>
impl<M, F> Aberration<M, F>
sourcepub fn as_ref(&self) -> Aberration<&M, &F>
pub fn as_ref(&self) -> Aberration<&M, &F>
Converts from &Aberration<M, F>
to Aberration<&M, &F>
.
Produces a new Aberration
, containing a reference into the original,
leaving it in place.
Examples
let x: Aberration<u32, &str> = Aberration::Mistake(42);
assert_eq!(x.as_ref(), Aberration::Mistake(&42));
let x: Aberration<&str, u32> = Aberration::Failure(47);
assert_eq!(x.as_ref(), Aberration::Failure(&47));
sourcepub fn as_mut(&mut self) -> Aberration<&mut M, &mut F>
pub fn as_mut(&mut self) -> Aberration<&mut M, &mut F>
Converts from &mut Aberration<M, F>
to Aberration<&mut M, &mut F>
Examples
fn mutate(x: &mut Aberration<u32, i32>) {
match x.as_mut() {
Aberration::Mistake(m) => *m = 42,
Aberration::Failure(f) => *f = 47,
}
}
let mut x: Aberration<u32, i32> = Aberration::Mistake(1);
mutate(&mut x);
assert_eq!(x.unwrap_mistake(), 42);
let mut x: Aberration<u32, i32> = Aberration::Failure(1);
mutate(&mut x);
assert_eq!(x.unwrap_failure(), 47);
sourcepub fn is_mistake(&self) -> bool
pub fn is_mistake(&self) -> bool
Returns true
if the aberration is a Mistake
Examples
Basic usage:
let x: Aberration<u32, i32> = Aberration::Mistake(42);
assert!(x.is_mistake());
let x: Aberration<u32, i32> = Aberration::Failure(47);
assert!(!x.is_mistake());
sourcepub fn is_failure(&self) -> bool
pub fn is_failure(&self) -> bool
Returns true
if the aberration is a Failure
Examples
Basic usage:
let x: Aberration<u32, i32> = Aberration::Failure(1);
assert!(x.is_failure());
let x: Aberration<u32, i32> = Aberration::Mistake(1);
assert!(!x.is_failure());
sourcepub fn mistake(self) -> Option<M>
pub fn mistake(self) -> Option<M>
Converts from Aberration<M, F>
to Option<M>
Converts self
into an Option<M>
, consuming self
, and discarding
the failure value if any.
Examples
let x: Aberration<u32, i32> = Aberration::Failure(42);
assert_eq!(x.mistake(), None);
let x: Aberration<u32, i32> = Aberration::Mistake(42);
assert_eq!(x.mistake(), Some(42));
sourcepub fn failure(self) -> Option<F>
pub fn failure(self) -> Option<F>
Converts from Aberration<M, F>
to Option<F>
Converts self
into an Option<F>
, consuming self
, and discarding the
mistake value if any.
Examples
let x: Aberration<u32, i32> = Aberration::Failure(42);
assert_eq!(x.failure(), Some(42));
let x: Aberration<u32, i32> = Aberration::Mistake(42);
assert_eq!(x.failure(), None);
sourcepub fn map_mistake<N, C>(self, callable: C) -> Aberration<N, F> where
C: FnOnce(M) -> N,
pub fn map_mistake<N, C>(self, callable: C) -> Aberration<N, F> where
C: FnOnce(M) -> N,
sourcepub fn map_failure<G, C>(self, callable: C) -> Aberration<M, G> where
C: FnOnce(F) -> G,
pub fn map_failure<G, C>(self, callable: C) -> Aberration<M, G> where
C: FnOnce(F) -> G,
sourceimpl<M, F: Debug> Aberration<M, F>
impl<M, F: Debug> Aberration<M, F>
sourcepub fn unwrap_mistake(self) -> M
pub fn unwrap_mistake(self) -> M
Returns the contained Mistake
value, consuming the self
value.
Panics
Panics if the value is a Failure
, with a custom panic message
provided by the failure.
Examples
let x: Aberration<&str, i32> = Aberration::Failure(47);
x.unwrap_mistake(); // panics with '47'
let x: Aberration<&str, i32> = Aberration::Mistake("try again!");
assert_eq!(x.unwrap_mistake(), "try again!");
sourceimpl<M: Debug, F> Aberration<M, F>
impl<M: Debug, F> Aberration<M, F>
sourcepub fn unwrap_failure(self) -> F
pub fn unwrap_failure(self) -> F
Returns the contained Failure
value, consuming the self
value.
Panics
Panics if the value is a Mistake
, with a custom panic message
provided by the mistake.
Examples
let x: Aberration<i32, &str> = Aberration::Mistake(47);
x.unwrap_failure(); // panics with '47'
let x: Aberration<i32, &str> = Aberration::Failure("error!");
assert_eq!(x.unwrap_failure(), "error!");
Trait Implementations
sourceimpl<M: Clone, F: Clone> Clone for Aberration<M, F>
impl<M: Clone, F: Clone> Clone for Aberration<M, F>
sourceimpl<M: Debug, F: Debug> Debug for Aberration<M, F>
impl<M: Debug, F: Debug> Debug for Aberration<M, F>
sourceimpl<S, M, F, N: From<M>, G: From<F>> FromResidual<Aberration<M, F>> for Outcome<S, N, G>
Available on crate feature nightly
only.
impl<S, M, F, N: From<M>, G: From<F>> FromResidual<Aberration<M, F>> for Outcome<S, N, G>
nightly
only.sourcefn from_residual(residual: Aberration<M, F>) -> Self
fn from_residual(residual: Aberration<M, F>) -> Self
try_trait_v2
)Constructs the type from a compatible Residual
type. Read more
sourceimpl<M, E, F: From<E>> FromResidual<Result<Infallible, E>> for Aberration<M, F>
Available on crate feature nightly
only.
impl<M, E, F: From<E>> FromResidual<Result<Infallible, E>> for Aberration<M, F>
nightly
only.sourcefn from_residual(residual: Result<Infallible, E>) -> Self
fn from_residual(residual: Result<Infallible, E>) -> Self
try_trait_v2
)Constructs the type from a compatible Residual
type. Read more
sourceimpl<M: Hash, F: Hash> Hash for Aberration<M, F>
impl<M: Hash, F: Hash> Hash for Aberration<M, F>
sourceimpl<M: Ord, F: Ord> Ord for Aberration<M, F>
impl<M: Ord, F: Ord> Ord for Aberration<M, F>
sourceimpl<M: PartialEq, F: PartialEq> PartialEq<Aberration<M, F>> for Aberration<M, F>
impl<M: PartialEq, F: PartialEq> PartialEq<Aberration<M, F>> for Aberration<M, F>
sourcefn eq(&self, other: &Aberration<M, F>) -> bool
fn eq(&self, other: &Aberration<M, F>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &Aberration<M, F>) -> bool
fn ne(&self, other: &Aberration<M, F>) -> bool
This method tests for !=
.
sourceimpl<M: PartialOrd, F: PartialOrd> PartialOrd<Aberration<M, F>> for Aberration<M, F>
impl<M: PartialOrd, F: PartialOrd> PartialOrd<Aberration<M, F>> for Aberration<M, F>
sourcefn partial_cmp(&self, other: &Aberration<M, F>) -> Option<Ordering>
fn partial_cmp(&self, other: &Aberration<M, F>) -> 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
sourceimpl<M: Debug, F: Debug> Termination for Aberration<M, F>
impl<M: Debug, F: Debug> Termination for Aberration<M, F>
sourceimpl<M, F> Try for Aberration<M, F>
Available on crate feature nightly
only.
impl<M, F> Try for Aberration<M, F>
nightly
only.type Output = M
type Output = M
try_trait_v2
)The type of the value produced by ?
when not short-circuiting.
type Residual = Result<Infallible, F>
type Residual = Result<Infallible, F>
try_trait_v2
)The type of the value passed to FromResidual::from_residual
as part of ?
when short-circuiting. Read more
sourcefn from_output(output: Self::Output) -> Self
fn from_output(output: Self::Output) -> Self
try_trait_v2
)Constructs the type from its Output
type. Read more
sourcefn branch(self) -> ControlFlow<Self::Residual, Self::Output>
fn branch(self) -> ControlFlow<Self::Residual, Self::Output>
try_trait_v2
)Used in ?
to decide whether the operator should produce a value
(because this returned ControlFlow::Continue
)
or propagate a value back to the caller
(because this returned ControlFlow::Break
). Read more
sourceimpl<M, E> WrapFailure for Aberration<M, E> where
E: Error + Send + Sync + 'static,
Available on crate feature report
only.
impl<M, E> WrapFailure for Aberration<M, E> where
E: Error + Send + Sync + 'static,
report
only.type Return = Aberration<M, Report>
type Return = Aberration<M, Report>
The expected return type for an impl
. Read more
sourcefn wrap_failure_with<D, F>(self, message: F) -> Self::Return where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D,
fn wrap_failure_with<D, F>(self, message: F) -> Self::Return where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D,
Wrap the failure value with a new adhoc error that is evaluated lazily only once an error does occur. Read more
sourcefn wrap_failure<D>(self, message: D) -> Self::Return where
D: Display + Send + Sync + 'static,
fn wrap_failure<D>(self, message: D) -> Self::Return where
D: Display + Send + Sync + 'static,
Wrap the failure value with a new adhoc error.
sourceimpl<M, E> WrapFailure for Aberration<M, E> where
E: Diagnostic + Send + Sync + 'static,
Available on crate feature diagnostic
only.
impl<M, E> WrapFailure for Aberration<M, E> where
E: Diagnostic + Send + Sync + 'static,
diagnostic
only.type Return = Aberration<M, Report>
type Return = Aberration<M, Report>
The expected return type for an impl
. Read more
sourcefn wrap_failure_with<D, F>(self, message: F) -> Self::Return where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D,
fn wrap_failure_with<D, F>(self, message: F) -> Self::Return where
D: Display + Send + Sync + 'static,
F: FnOnce() -> D,
Wrap the failure value with a new adhoc error that is evaluated lazily only once an error does occur. Read more
sourcefn wrap_failure<D>(self, message: D) -> Self::Return where
D: Display + Send + Sync + 'static,
fn wrap_failure<D>(self, message: D) -> Self::Return where
D: Display + Send + Sync + 'static,
Wrap the failure value with a new adhoc error.
impl<M: Copy, F: Copy> Copy for Aberration<M, F>
impl<M: Eq, F: Eq> Eq for Aberration<M, F>
impl<M, F> StructuralEq for Aberration<M, F>
impl<M, F> StructuralPartialEq for Aberration<M, F>
Auto Trait Implementations
impl<M, F> RefUnwindSafe for Aberration<M, F> where
F: RefUnwindSafe,
M: RefUnwindSafe,
impl<M, F> Send for Aberration<M, F> where
F: Send,
M: Send,
impl<M, F> Sync for Aberration<M, F> where
F: Sync,
M: Sync,
impl<M, F> Unpin for Aberration<M, F> where
F: Unpin,
M: Unpin,
impl<M, F> UnwindSafe for Aberration<M, F> where
F: UnwindSafe,
M: UnwindSafe,
Blanket Implementations
sourceimpl<T, U> AttemptFrom<U> for T where
U: Into<T>,
impl<T, U> AttemptFrom<U> for T where
U: Into<T>,
type Mistake = Infallible
type Mistake = Infallible
The retryable error type
type Failure = Infallible
type Failure = Infallible
The failure error type
sourcefn attempt_from(
value: U
) -> Outcome<T, <T as AttemptFrom<U>>::Mistake, <T as AttemptFrom<U>>::Failure>
fn attempt_from(
value: U
) -> Outcome<T, <T as AttemptFrom<U>>::Mistake, <T as AttemptFrom<U>>::Failure>
Performs the conversion
sourceimpl<T, U> AttemptInto<U> for T where
U: AttemptFrom<T>,
impl<T, U> AttemptInto<U> for T where
U: AttemptFrom<T>,
type Mistake = <U as AttemptFrom<T>>::Mistake
type Mistake = <U as AttemptFrom<T>>::Mistake
The type returned in the event of a conversion error where the caller may retry the conversion. Read more
type Failure = <U as AttemptFrom<T>>::Failure
type Failure = <U as AttemptFrom<T>>::Failure
The type returned in the event of a conversion error where the caller may not retry the conversion. Read more
sourcefn attempt_into(
self
) -> Outcome<U, <T as AttemptInto<U>>::Mistake, <T as AttemptInto<U>>::Failure>
fn attempt_into(
self
) -> Outcome<U, <T as AttemptInto<U>>::Mistake, <T as AttemptInto<U>>::Failure>
Performs the conversion.
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