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);

Maps an Aberration<M, F> to Aberration<N, F> by applying a function to a contained Mistake value, leaving any Failure value untouched.

Maps an Aberration<M, F> to Aberration<M, G> by applying a function to a contained Failure value, leaving any Mistake value untouched.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

🔬 This is a nightly-only experimental API. (try_trait_v2)

Constructs the type from a compatible Residual type. Read more

🔬 This is a nightly-only experimental API. (try_trait_v2)

Constructs the type from a compatible Residual type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Is called to get the representation of the value as status code. This status code is returned to the operating system. Read more

🔬 This is a nightly-only experimental API. (try_trait_v2)

The type of the value produced by ? when not short-circuiting.

🔬 This is a nightly-only experimental API. (try_trait_v2)

The type of the value passed to FromResidual::from_residual as part of ? when short-circuiting. Read more

🔬 This is a nightly-only experimental API. (try_trait_v2)

Constructs the type from its Output type. Read more

🔬 This is a nightly-only experimental API. (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

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

Compatibility re-export of wrap_failure for interop with anyhow and eyre. Read more

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

Compatibility re-export of wrap_failure for interop with anyhow and eyre. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

The retryable error type

The failure error type

Performs the conversion

The type returned in the event of a conversion error where the caller may retry the conversion. Read more

The type returned in the event of a conversion error where the caller may not retry the conversion. Read more

Performs the conversion.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.