Trait some_to_err::SomeToErr
source · pub trait SomeToErr {
type Err;
// Required method
fn some_to_err<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::SomeToErr;
let some: Option<&str> = Some("Error");
let result = some.some_to_err(42);
assert_eq!(result, Err("Error"));use some_to_err::SomeToErr;
let none: Option<&str> = None;
let result = none.some_to_err(42);
assert_eq!(result, Ok(42));