ErrOr

Trait ErrOr 

Source
pub trait ErrOr {
    type Err;

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

The SomeErr trait provides a method for converting an Option into a Result by treating Some values as Err and None values as Ok.

§Examples

use some_to_err::ErrOr;

let some: Option<&str> = Some("Error");
let result = some.err_or(42);
assert_eq!(result, Err("Error"));
use some_to_err::ErrOr;

let none: Option<&str> = None;
let result = none.err_or(42);
assert_eq!(result, Ok(42));

Required Associated Types§

Required Methods§

Source

fn err_or<OK>(self, ok: OK) -> Result<OK, Self::Err>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> ErrOr for Option<T>

Source§

type Err = T

Source§

fn err_or<OK>(self, ok: OK) -> Result<OK, Self::Err>

Implementors§