pub enum Concern<S, M> {
    Success(S),
    Mistake(M),
}
Expand description

Concern is a type that can represent a Success, or Mistake.

NOTE: This type will become a type alias once ! is stabilized.

See the module documentation for more usage details.

Variants

Success(S)

Contains the success value

Mistake(M)

Contains the mistake value

Implementations

Converts from &Concern<S, M> to Concern<&S, &M>.

Produces a new Concern, containing a reference into the original, leaving it in place.

Examples
let x: Concern<u32, &str> = Concern::Success(42);
assert_eq!(x.as_ref(), Concern::Success(&42));

let x: Concern<u32, i32> = Concern::Mistake(47);
assert_eq!(x.as_ref(), Concern::Mistake(&47));

Converts from &mut Concern<S, M> to Concern<&mut S, &mut F>

Examples
fn mutate(c: &mut Concern<u32, i32>) {
  match c.as_mut() {
    Concern::Success(s) => *s = 47,
    Concern::Mistake(m) => *m = 19,
  }
}

let mut x: Concern<u32, i32> = Concern::Success(42);
mutate(&mut x);
assert_eq!(x.unwrap(), 47);

let mut x: Concern<u32, i32> = Concern::Mistake(47);
mutate(&mut x);
assert_eq!(x.unwrap_mistake(), 19);

Returns an iterator over the possibly contained value.

The iterator yields one value if the outcome is Success, otherwise none.

Examples

Basic usage:

let x: Concern<u32, i32> = Concern::Success(42);
assert_eq!(x.iter().next(), Some(&42));

let x: Concern<u32, i32> = Concern::Mistake(47);
assert_eq!(x.iter().next(), None);

Returns a mutable iterator over the possibly contained value.

The iterator yields one value if the result is Success, otherwise none.

Examples
let mut x: Concern<i32, &str> = Concern::Success(7);
match x.iter_mut().next() {
  Some(v) => *v += 40,
  None => {}
}
assert_eq!(x, Concern::Success(47));

Returns true if the concern is a Success

Examples

Basic usage:

let x: Concern<u32, &str> = Concern::Success(42);
assert!(x.is_success());

let x: Concern<u32, &str> = Concern::Mistake("hello");
assert!(!x.is_success());

Returns true if the concern is a Mistake

Examples
let x: Concern<u32, &str> = Concern::Success(42);
assert!(!x.is_mistake());

let x: Concern<u32, &str> = Concern::Mistake("hello");
assert!(x.is_mistake());

Converts from Concern<S, M> to Option<S>

Converts self into an Option<S>, consuming self, and discarding the mistake, if any.

Examples
let x: Concern<u32, &str> = Concern::Success(42);
assert_eq!(x.success(), Some(42));

let x: Concern<u32, &str> = Concern::Mistake("hello");
assert_eq!(x.success(), None);

Converts from Concern<S, M> to Option<M>

Converts self into an Option<M>, consuming self, and discarding the success, if any.

Examples
let x: Concern<u32, &str> = Concern::Success(42);
assert_eq!(x.mistake(), None);

let x: Concern<u32, &str> = Concern::Mistake("hello");
assert_eq!(x.mistake(), Some("hello"));

Maps a Concern<S, M> to Concern<T, F> by applying a function to a contained Success value, leaving any Mistake value untouched.

Examples
let x: Concern<u32, &str> = Concern::Success(42);
assert_eq!(x.map(|x| x + 1), Concern::Success(43));

let x: Concern<u32, &str> = Concern::Mistake("hello");
assert_eq!(x.map(|x| x + 1), Concern::Mistake("hello"));

Maps a Concern<S, M> to Concern<S, N> by applying a function to a contained Mistake value, leaving any Success value untouched.

Examples
let x: Concern<u32, i32> = Concern::Success(42);
assert_eq!(x.map_mistake(|x| x + 1), Concern::Success(42));

let x: Concern<u32, i32> = Concern::Mistake(46);
assert_eq!(x.map_mistake(|x| x + 1), Concern::Mistake(47));

Returns the contained Success value, consuming the self value.

Panics

Panics if the value is a Mistake with a panic message provided by their value.

Examples
let x: Concern<u32, &str> = Concern::Success(42);
assert_eq!(x.unwrap(), 42);
let x: Concern<u32, &str> = Concern::Mistake("hello");
x.unwrap(); // panics with "hello"

Returns the contained Mistake value, consuming the self value.

Panics

Panics if the value is a Success with a panic message provided by their value.

Examples
let x: Concern<u32, &str> = Concern::Mistake("hello");
assert_eq!(x.unwrap_mistake(), "hello");
let x: Concern<u32, &str> = Concern::Success(42);
x.unwrap_mistake(); // panics with "42"

Converts from Concern<S, M> (or &Concern<S, M>) to Concern<&<S as Deref>::Target, M>.

Coerces the Success variant of the original Concern via Deref and returns the new Concern.

Examples
let x: Concern<String, u32> = Concern::Success("hello".to_string());
let y: Concern<&str, &u32> = Concern::Success("hello");
assert_eq!(x.as_deref(), y);

Converts from Concern<S, M> (or &mut Concern<S, M>) to Concern<&mut <S as DerefMut>::Target, &mut M>.

Coerces the Success variant of the original Concern via DerefMut and returns the new Concern

Examples
let mut s = "HELLO".to_string();
let mut x: Concern<String, u32> = Concern::Success("hello".to_string());
let y: Concern<&mut str, &mut u32> = Concern::Success(&mut s);
assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y);

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

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

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.