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
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));
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);
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());
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());
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));
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);
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!");
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
impl<S, M, F, N: From<M>, G: From<F>> FromResidual<Aberration<M, F>> for Outcome<S, N, G>
This is supported 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.try_trait_v2
)Constructs the type from a compatible Residual
type. Read more
impl<M, E, F: From<E>> FromResidual<Result<Infallible, E>> for Aberration<M, F>
This is supported on crate feature nightly
only.
impl<M, E, F: From<E>> FromResidual<Result<Infallible, E>> for Aberration<M, F>
nightly
only.try_trait_v2
)Constructs the type from a compatible Residual
type. Read more
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<M: Debug, F: Debug> Termination for Aberration<M, F>
This is supported on crate feature nightly
only.
impl<M: Debug, F: Debug> Termination 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
try_trait_v2
)Constructs the type from its Output
type. Read more
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
impl<M, E> WrapFailure for Aberration<M, E> where
E: Error + Send + Sync + 'static,
This is supported 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
Wrap the failure value with a new adhoc error that is evaluated lazily only once an error does occur. Read more
Wrap the failure value with a new adhoc error.
Compatibility re-export of wrap_failure_with
for interop with
anyhow
and eyre
. Read more
impl<M, E> WrapFailure for Aberration<M, E> where
E: Diagnostic + Send + Sync + 'static,
This is supported 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
Wrap the failure value with a new adhoc error that is evaluated lazily only once an error does occur. Read more
Wrap the failure value with a new adhoc error.
Compatibility re-export of wrap_failure_with
for interop with
anyhow
and eyre
. Read more
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
type Mistake = Infallible
type Mistake = Infallible
The retryable error type
type Failure = Infallible
type Failure = Infallible
The failure error type
pub fn attempt_from(
U
) -> Outcome<T, <T as AttemptFrom<U>>::Mistake, <T as AttemptFrom<U>>::Failure>
pub fn attempt_from(
U
) -> Outcome<T, <T as AttemptFrom<U>>::Mistake, <T as AttemptFrom<U>>::Failure>
Performs the conversion
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
pub fn attempt_into(
Self
) -> Outcome<U, <T as AttemptInto<U>>::Mistake, <T as AttemptInto<U>>::Failure>
pub fn attempt_into(
Self
) -> Outcome<U, <T as AttemptInto<U>>::Mistake, <T as AttemptInto<U>>::Failure>
Performs the conversion.
Mutably borrows from an owned value. Read more