Trait outcome::AttemptInto[][src]

pub trait AttemptInto<T>: Sized {
    type Mistake;
    type Failure;
    fn attempt_into(self) -> Outcome<T, Self::Mistake, Self::Failure>;
}
Expand description

An attempted conversion that consumes self, which may or may not be expensive. Outcome’s analogue to TryInto.

Library writers should usually not implement this trait directly, but should prefer implementing the AttemptFrom trait, which offers more flexibility and provides an equivalent AttemptInto implementation for free, thanks to the blanket implementation provided by the outcome crate.

Unlike TryInto, users are free to return a retryable error, which should return the data consumed.

let y = -1i8;
let x: Outcome<u128, i8, Box<dyn std::error::Error>> = y.attempt_into();
match x {
  // y's original value, which we can retrieve if desired.
  Mistake(y) => { return y; },
  _ => { /* ... */ }
}

For more information on this, see the documentation for Into.

Associated Types

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

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

Required methods

Performs the conversion.

Implementors