pub trait SomeToErrElse {
    type Err;

    // Required method
    fn some_to_err_else<OK>(
        self,
        ok: impl FnOnce() -> OK
    ) -> Result<OK, Self::Err>;
}
Expand description

The SomeToErrElse trait provides a convenient method to convert an Option<T> into a Result<OK, T> by supplying a closure that generates the OK value for the Result when the input is None.

Examples

Basic usage:

use some_to_err::SomeToErrElse;

let input: Option<&str> = None;
let result = input.some_to_err_else(|| "OK");
assert_eq!(result, Ok("OK"));
use some_to_err::SomeToErrElse;

let input = Some("Error");
let result = input.some_to_err_else(|| "OK");
assert_eq!(result, Err("Error"));

Required Associated Types§

Required Methods§

source

fn some_to_err_else<OK>(self, ok: impl FnOnce() -> OK) -> Result<OK, Self::Err>

Implementations on Foreign Types§

source§

impl<T> SomeToErrElse for Option<T>

§

type Err = T

source§

fn some_to_err_else<OK>(self, ok: impl FnOnce() -> OK) -> Result<OK, Self::Err>

Implementors§