pub enum Outcome<S, M, F> {
    Success(S),
    Mistake(M),
    Failure(F),
}
Expand description

Outcome is a type that represents a Success, Mistake, or Failure.

See the module documentation for more details.

Example

The following example shows using Outcome to wrap Mutex<T> to create a spin lock with exponential backoff, that will not block and is adapted from the C++ code in the blog post Using locks in real-time audio processing, safely.

This is not meant to be an example of good API design, but to show how Outcome can be used to make retryable APIs easier to work with.

use std::sync::{Mutex, MutexGuard, PoisonError, LockResult, TryLockError};
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::_mm_pause;
#[cfg(target_arch = "x86")]
use std::arch::x86::_mm_pause;

#[cfg(not(any(target_arch = "x86_64", target_arch="x86")))]
#[inline(never)]
unsafe fn _mm_pause() { }

struct WouldBlock;

struct SpinMutex<T: ?Sized> {
  inner: Mutex<T>,
}

type TryLockOutcome<'a, T> = Outcome<
  MutexGuard<'a, T>,
  WouldBlock,
  PoisonError<MutexGuard<'a, T>>
>;

impl<T> SpinMutex<T> {
  pub fn try_lock(&self) -> TryLockOutcome<T> {
    match self.inner.try_lock() {
      Err(TryLockError::Poisoned(f)) => Failure(f),
      Err(TryLockError::WouldBlock) => Mistake(WouldBlock),
      Ok(s) => Success(s),
    }
  }

  pub fn lock(&self) -> LockResult<MutexGuard<'_, T>> {
    for _ in 0..5 {
      match self.try_lock() {
        Success(s) => { return Ok(s); }
        Mistake(_) => { continue; }
        Failure(f) => { return Err(f); }
      }
    }

    for _ in 0..10 {
      match self.try_lock() {
        Success(s) => { return Ok(s); }
        Mistake(_) => { unsafe { _mm_pause(); } }
        Failure(f) => { return Err(f); }
      }
    }

    let mut n = 0;
    loop {
      for _ in 0..3000 {
        match self.try_lock() {
          Success(s) => { return Ok(s); }
          Mistake(_) => {
            for _ in 0..10 { unsafe { _mm_pause(); } }
            continue;
          }
          Failure(f) => { return Err(f); }
        }
      }
      std::thread::yield_now();
      n += 1;
      if n >= 2 { break self.inner.lock(); }
    }
  }
}

Variants

Success(S)

Contains the success value

Mistake(M)

Contains the mistake value

Failure(F)

Contains the failure value

Implementations

Available on crate feature unstable only.

Returns true if the outcome is a Success value containing the given value.

Examples
let x: Outcome<u32, f32, &str> = Success(47);
assert_eq!(x.contains(&47), true);

let x: Outcome<u32, f32, &str> = Success(47);
assert_eq!(x.contains(&42), false);

let x: Outcome<u32, f32, &str> = Mistake(0.0f32);
assert_eq!(x.contains(&47), false);

let x: Outcome<u32, f32, &str> = Failure("Some error message");
assert_eq!(x.contains(&47), false);
Available on crate feature unstable only.

Returns true if the outcome is a Mistake value containing the given value.

Examples

let x: Outcome<u32, &str, i32> = Success(47);
assert_eq!(x.contains_mistake(&"Some mistake message"), false);

let x: Outcome<u32, &str, i32> = Mistake("Some mistake message");
assert_eq!(x.contains_mistake(&"Some mistake message"), true);

let x: Outcome<u32, &str, i32> = Mistake("Some other mistake message");
assert_eq!(x.contains_mistake(&"Some mistake message"), false);

let x: Outcome<u32, &str, i32> = Failure(47);
assert_eq!(x.contains_mistake(&"Some error message"), false);
Available on crate feature unstable only.

Returns true if the outcome is a Failure value containing the given value.

Examples

let x: Outcome<u32, i32, &str> = Success(47);
assert_eq!(x.contains_failure(&"Some error message"), false);

let x: Outcome<u32, i32, &str> = Mistake(47);
assert_eq!(x.contains_failure(&"Some error message"), false);

let x: Outcome<u32, i32, &str> = Failure("Some error message");
assert_eq!(x.contains_failure(&"Some error message"), true);

let x: Outcome<u32, u32, &str> = Failure("Some other error message");
assert_eq!(x.contains_failure(&"Some error message"), false);
Available on crate feature unstable only.

Converts from Outcome<Outcome<S, M, F>, M, F> to Outcome<S, M, F>

Examples
let x: Outcome<Outcome<&'static str, u32, u32>, u32, u32> = Success(Success("hello"));
assert_eq!(Success("hello"), x.flatten());

let x: Outcome<Outcome<&'static str, u32, u32>, u32, u32> = Success(Mistake(47));
assert_eq!(Mistake(47), x.flatten());

let x: Outcome<Outcome<&'static str, u32, u32>, u32, u32> = Success(Failure(47));
assert_eq!(Failure(47), x.flatten());

let x: Outcome<Outcome<&'static str, u32, u32>, u32, u32> = Mistake(47);
assert_eq!(Mistake(47), x.flatten());

let x: Outcome<Outcome<&'static str, u32, u32>, u32, u32> = Failure(47);
assert_eq!(Failure(47), x.flatten());

NOTE: Flattening only removes one level of nesting at a time:

type Nested<T> = Outcome<Outcome<Outcome<T, u32, u32>, u32, u32>, u32, u32>;
let x: Nested<&'static str> = Success(Success(Success("hello")));
assert_eq!(Success(Success("hello")), x.flatten());
assert_eq!(Success("hello"), x.flatten().flatten());
Available on crate feature nightly only.

TODO: write documentation

Available on crate feature nightly only.

Escalates an Outcome from a Mistake to a Failure

Available on crate feature nightly only.

Escalates an Outcome from a Mistake to a Failure using the given closure.

Available on crate feature nightly only.

Returns the contained Success value, but never panics.

Unlike unwrap, this method is known to never panic on the outcome types it is implemented for. Therefore, it can be used instead of unwrap as a maintainability safeguard that will fail to compile if the mistake or failure type of the Outcome is later changed to mistake or failure that can actually occur.

Examples
fn only_success() -> Outcome<String, !, !> {
  Success("This is fine 🐶☕🔥".into())
}

let s: String = only_success().into_success();
assert!(s.contains("This is fine"));
Available on crate feature nightly only.

Returns the contained Mistake value, but never panics.

Unlike unwrap_mistake, this method is known to never panic on the outcome types it is implemented for. Therefore it can be used instead of unwrap_mistake as a maintainibility safeguard that will fail to compile if the success or failure type of the Outcome is later changed to a success or failure that can actually occur.

Examples
fn only_mistake() -> Outcome<!, String, !> {
  Mistake("Try another! 🍾🔫🤠".into())
}

let s: String = only_mistake().into_mistake();
assert!(s.contains("Try another!"));
Available on crate feature nightly only.

Returns the contained Failure value, but never panics.

Unlike unwrap_failure, this method is known to never panic on the outcome types it is implemented for. Therefore, it can be used instead of unwrap_failure as a maintainibility safeguard that will fail to compile if the success or mistake type of the Outcome is later changed to a success or mistake that can actually occur.

fn only_failure() -> Outcome<!, !, String> {
  Failure("Catarina! 👦🤚🪑👧".into())
}

let s: String = only_failure().into_failure();
assert!(s.contains("Catarina!"));

Converts from &Outcome<S, M, F> to Outcome<&S, &M, &F>.

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

Examples
let x: Outcome<u32, f32, &str> = Success(2);
assert_eq!(x.as_ref(), Success(&2));

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

let x: Outcome<i32, i32, i32> = Failure(42);
assert_eq!(x.as_ref(), Failure(&42));

Converts from &mut Outcome<S, M, F> to Outcome<&mut S, &mut M, &mut F>.

Examples
fn mutate(o: &mut Outcome<i32, i32, i32>) {
  match o.as_mut() {
    Success(s) => *s = 47,
    Mistake(m) => *m = 19,
    Failure(f) => *f = 0,
  }
}

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

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

let mut x: Outcome<i32, i32, i32> = Failure(47);
mutate(&mut x);
assert_eq!(x.unwrap_failure(), 0);

Returns a Result<Concern<S, M>, F>, which allows a user to still rely on the ? operator until Try has been stabilized.

Examples

pub fn invoke() -> Result<u32, &'static str> {
  let x: Outcome<u32, f32, &str> = Success(2);
  let c = x.acclimate()?;
  Ok(match c {
    Concern::Success(s) => s,
    Concern::Mistake(m) => m as u32,
  })
}

Returns an iterator over the possibly contained value.

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

Examples

Basic usage:

let x: Outcome<i32, f32, &str> = Success(47);
assert_eq!(x.iter().next(), Some(&47));

let x: Outcome<i32, f32, &str> = Mistake(0.0f32);
assert_eq!(x.iter().next(), None);

let x: Outcome<i32, f32, &str> = Failure("nope!");
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: Outcome<i32, f32, &str> = Success(7);
match x.iter_mut().next() {
  Some(v) => *v += 40,
  None => {}
}
assert_eq!(x, Success(47));

Returns true if the outcome is Success.

Examples

Basic usage:

let x: Outcome<i32, (), &str> = Success(-1);
assert!(x.is_success());

let x: Outcome<i32, (), &str> = Mistake(());
assert!(!x.is_success());

let x: Outcome<i32, (), &str> = Failure("Some failure message");
assert!(!x.is_success());

Returns true if the outcome is Mistake.

Examples
let x: Outcome<(), i32, &str> = Mistake(-1);
assert!(x.is_mistake());

let x: Outcome<(), i32, &str> = Success(());
assert!(!x.is_mistake());

let x: Outcome<(), i32, &str> = Failure("Some failure message");
assert!(!x.is_mistake());

Returns true if the outcome is Failure.

Examples
let x: Outcome<i32, f32, &str> = Failure("some failure message");
assert!(x.is_failure());

let x: Outcome<i32, f32, &str> = Mistake(0.0f32);
assert!(!x.is_failure());

let x: Outcome<i32, f32, &str> = Success(-1);
assert!(!x.is_failure());

Returns true if the outcome is not Success

Examples
let x: Outcome<i32, f32, &str> = Failure("some failure message");
assert!(x.is_error());

let x: Outcome<i32, f32, &str> = Mistake(0.0f32);
assert!(x.is_error());

let x: Outcome<i32, f32, &str> = Success(-1);
assert!(!x.is_error());

Converts from Outcome<S, M, F> to Option<S>.

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

Examples
let outcome: Outcome<i32, f32, &str> = Success(4);
assert_eq!(outcome.success(), Some(4));

let outcome: Outcome<i32, f32, &str> = Mistake(0.0);
assert_eq!(outcome.success(), None);

let outcome: Outcome<i32, f32, &str> = Failure("failure");
assert_eq!(outcome.success(), None);

Converts from Outcome<S, M, F> to Option<M>.

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

Examples
let outcome: Outcome<f32, i32, &str> = Mistake(47);
assert_eq!(outcome.mistake(), Some(47));

let outcome: Outcome<f32, i32, &str> = Success(0.0);
assert_eq!(outcome.mistake(), None);

let outcome: Outcome<f32, i32, &str> = Failure("failure");
assert_eq!(outcome.mistake(), None);

Converts from Outcome<S, M, F> to Option<F>.

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

Examples
let outcome: Outcome<f32, (), i32> = Success(0.0);
assert_eq!(outcome.failure(), None);

let outcome: Outcome<f32, (), i32> = Mistake(());
assert_eq!(outcome.failure(), None);

let outcome: Outcome<f32, (), i32> = Failure(-1);
assert_eq!(outcome.failure(), Some(-1));

Returns the contained Success value, consuming the self value, without checking that the value is not a Mistake or Failure.

Safety

Calling this method on a Mistake or Failure is undefined behavior

Examples
let x: Outcome<u32, f32, &str> = Success(47);
assert_eq!(unsafe { x.unwrap_unchecked() }, 47);
let x: Outcome<u32, f32, &str> = Mistake(0.0f32);
unsafe { x.unwrap_unchecked(); } // Undefined Behavior!
let x: Outcome<u32, f32, &str> = Failure("emergency!");
unsafe { x.unwrap_unchecked(); } // Undefined Behavior!

Returns the contained Mistake value, consuming the self value, without checking that the value is not a Success or Failure.

Safety

Calling this method on a Success or Failure is undefined behavior

Examples
let x: Outcome<u32, f32, &str> = Success(47);
unsafe { x.unwrap_mistake_unchecked(); } // Undefined Behavior!
let x: Outcome<u32, i32, &str> = Mistake(47);
assert_eq!(unsafe { x.unwrap_mistake_unchecked() }, 47);
let x: Outcome<u32, f32, &str> = Failure("emergency!");
unsafe { x.unwrap_mistake_unchecked(); } // Undefined Behavior!!

Returns the contained Failure value, consuming the self value without checking that the value is not a Success or Mistake.

Safety

Calling this method on a Success or Mistake is undefined behavior

Examples
let x: Outcome<u32, f32, &str> = Success(47);
unsafe { x.unwrap_failure_unchecked(); } // Undefined Behavior!
let x: Outcome<u32, i32, &str> = Mistake(47);
unsafe { x.unwrap_failure_unchecked() }; // Undefined Behavior!
let x: Outcome<u32, f32, &str> = Failure("emergency!");
assert_eq!(unsafe { x.unwrap_failure_unchecked() }, "emergency!");

Calls op if the result is Success, otherwise returns the Mistake or Failure value of self.

This function can be used for control flow based on Outcome values.

Examples

fn square(x: u32) -> Outcome<u32, u32, u32> { Success(x * x) }
fn mistake(x: u32) -> Outcome<u32, u32, u32> { Mistake(x) }
fn failure(x: u32) -> Outcome<u32, u32, u32> { Failure(0) }

assert_eq!(Success(2).and_then(square).and_then(square), Success(16));
assert_eq!(Success(2).and_then(square).and_then(failure), Failure(0));
assert_eq!(Success(2).and_then(square).and_then(mistake), Mistake(4));
assert_eq!(Failure(2).and_then(square).and_then(square), Failure(2));

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

This function can be used to compose the results of two functions.

Returns the provided default (if Mistake or Failure), or applies a function to the contained value (if Success).

Arguments passed to map_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use map_or_else, which is lazily evaluated.

Examples
 let x: Outcome<_, &str, &str> = Success("foo");
 assert_eq!(x.map_or(47, |v| v.len()), 3);

 let x: Outcome<&str, _, &str> = Mistake("bar");
 assert_eq!(x.map_or(47, |v| v.len()), 47);

 let x: Outcome<&str, &str, _> = Failure("baz");
 assert_eq!(x.map_or(47, |v| v.len()), 47);

Maps an Outcome<S, M, F> to T by applying a fallback function to a contained Mistake or Failure value (by way of an Aberration), or a default function to a contained Success value.

This function can be used to unpack a successful outcome while handling mistakes or failures.

Maps an Outcome<S, M, F> to Outcome<S, N, F> by applying a function to a contained Mistake value, leaving a Success or Failure value untouched.

This function can be used to pass through a successful outcome while handling a mistake.

Examples
let x: Outcome<&str, _, &str> = Mistake("foo");
assert_eq!(x.map_mistake(|v| v.len()), Mistake(3));

let x: Outcome<&str, &str, _> = Failure("bar");
assert_eq!(x.map_mistake(|v| v.len()), Failure("bar"));

let x: Outcome<_, &str, &str> = Success("baz");
assert_eq!(x.map_mistake(|v| v.len()), Success("baz"));

Maps an Outcome<S, M, F> to Outcome<S, M, G> by applying a function to a contained Failure value, leaving a Success or Failure value untouched.

This function can be used to pass through a successful or mistaken outcome while handling a failure.

Maps an Outcome<&S, M, F> to an Outcome<S, M, F> by cloning the contents of the Success value.

Examples
let val = 47;
let x: Outcome<&i32, u32, f32> = Success(&val);
assert_eq!(x, Success(&47));
let cloned = x.cloned();
assert_eq!(cloned, Success(47));

Maps an Outcome<&mut S, M, F> to an Outcome<S, M, F> by cloning the contents of the Success value.

Examples
let mut val = 47;
let x: Outcome<&mut i32, u32, i32> = Success(&mut val);
assert_eq!(x, Success(&mut 47));
let cloned = x.cloned();
assert_eq!(cloned, Success(47));

Maps an Outcome<&S, M, F> to an Outcome<S, M, F> by copying the contents of the Success value.

Examples
let value = 47;
let x: Outcome<&i32, i32, i32> = Success(&value);
assert_eq!(x, Success(&47));
let copied = x.copied();
assert_eq!(copied, Success(47));

Maps an Outcome<&mut S, M, F> to an Outcome<S, M, F> by copying the contents of the Success value.

Examples
let mut value = 47;
let x: Outcome<&mut i32, i32, i32> = Success(&mut value);
assert_eq!(x, Success(&mut 47));
let copied = x.copied();
assert_eq!(copied, Success(47));

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

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

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

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

Coerces the Success variant of the original Outcome via DerefMut and returns the new Outcome.

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

Returns the contained Success value, consuming the self value.

Because this function may panic, its use is generally discourged. Instead, prefer to use pattern matching and handle the Mistake or Failure case explicitly, or call unwrap_or, unwrap_or_else, or unwrap_or_default.

Panics

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

Examples
let x: Outcome<u32, &str, &str> = Success(2);
assert_eq!(x.unwrap(), 2);
let x: Outcome<u32, &str, &str> = Mistake("mistake");
x.unwrap(); // panics with `"mistake"`
let x: Outcome<u32, &str, &str> = Failure("emergency failure");
x.unwrap(); // panics with "emergency failure"

Returns the Success value or a provided default.

Arguments passed to unwrap_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use unwrap_or_else, which is lazily evaluated.

Examples
let x: Outcome<u32, &str, &str> = Success(2);
assert_eq!(x.unwrap_or(3), 2);

let x: Outcome<u32, &str, &str> = Mistake("mistaken");
assert_eq!(x.unwrap_or(3), 3);

let x: Outcome<u32, &str, &str> = Failure("emergency failure");
assert_eq!(x.unwrap_or(3), 3);

Returns the contained Success value or computes it from the closure.

Examples
let x: Outcome<u32, &str, &str> = Success(2);
assert_eq!(x.unwrap_or_else(|_| 3), 2);

let x: Outcome<u32, &str, &str> = Mistake("mistaken");
assert_eq!(x.unwrap_or_else(|_| 3), 3);

let x: Outcome<u32, &str, &str> = Failure("emergency failure");
assert_eq!(x.unwrap_or_else(|_| 3), 3);

Returns the contained Mistake value, consuming the self value.

Panics

Panics if the value is either a Success or Failure, with a custom panic message provided by either value.

Examples
let x: Outcome<u32, &str, &str> = Success(47);
x.unwrap_mistake(); // panics with '47'
let x: Outcome<u32, &str, f32> = Mistake("try again!");
assert_eq!(x.unwrap_mistake(), "try again!");
let x: Outcome<u32, &str, &str> = Failure("emergency failure");
x.unwrap_mistake(); // panics with 'emergency failure'

Returns the contained Failure value, consuming the self value.

Panics

Panics if the value is either a Success or Mistake, with a custom panic message provided by either value.

Examples
let x: Outcome<u32, &str, &str> = Success(47);
x.unwrap_failure(); // panics with 47
let x: Outcome<u32, &str, f32> = Mistake("try again!");
x.unwrap_failure(); // panics with 'try again!'
let x: Outcome<u32, f32, &str> = Failure("failure!");
assert_eq!(x.unwrap_failure(), "failure!");

Returns the contained Mistake or Failure value wrapped in an Aberration, consuming the self value.

Panics

Panics if the value is a Success, with a custom panic message provided by the contained value.

Examples
let x: Outcome<u32, &str, &str> = Success(47);
x.unwrap_error(); // panics with '47'
let x: Outcome<u32, &str, &str> = Failure("failure!");
let ab = x.unwrap_error();
match ab {
  Aberration::Mistake(m) => assert_eq!("mistake!", m),
  Aberration::Failure(f) => assert_eq!("failure!", f),
};

Returns the contained Success value or a default.

Consumes the self argument then, if Success, returns the contained value, otherwise if the outcome is a Mistake or Failure, returns the default value for Success

Transposes an Outcome of an Option into an Option of an Outcome.

  • Success(None) will be mapped to None.
  • Success(Some(_)), Mistake(_), and Failure(_) will be mapped to Some(Success(_)), Some(Mistake(_)), and Some(Failure(_)).
Examples
let x: Outcome<Option<u32>, &str, &str> = Success(Some(5));
let y: Option<Outcome<u32, &str, &str>> = Some(Success(5));
assert_eq!(x.transpose(), 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

🔬 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

🔬 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

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. 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

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.