stefans_utils/map.rs
1//! Contains the Map trait which collects the `ok`, `ok_or`, `map`, `unwrap` and `expect` functions as seen on TV
2
3use core::fmt;
4
5pub trait Map: Sized {
6 fn ok(self) -> Result<Self, Self>;
7 fn ok_or<E>(self, err: E) -> Result<Self, E>;
8 fn map<T>(self, f: impl FnOnce() -> T) -> Option<T>;
9 fn and_then<T>(self, f: impl FnOnce() -> Option<T>) -> Option<T>;
10 fn unwrap(self) -> Self;
11 fn expect(self, message: impl fmt::Display) -> Self;
12}