stefans-utils 0.12.0

A collection of useful Rust utility functions, types, and traits.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
//! Contains the Map trait which collects the `ok`, `ok_or`, `map`, `unwrap` and `expect` functions as seen on TV

use core::fmt;

pub trait Map: Sized {
    fn ok(self) -> Result<Self, Self>;
    fn ok_or<E>(self, err: E) -> Result<Self, E>;
    fn map<T>(self, f: impl FnOnce() -> T) -> Option<T>;
    fn and_then<T>(self, f: impl FnOnce() -> Option<T>) -> Option<T>;
    fn unwrap(self) -> Self;
    fn expect(self, message: impl fmt::Display) -> Self;
}