maybe-trait 1.0.0

Allows writing functions which are polymorphic over taking an option.
Documentation
//! This crate provides the `Maybe` trait which is implemented for
//! both `T` and `Option<T>`.  The purpose is so that you can write functions
//! like this:
//! ```rs
//! fn foo(param: impl Maybe<Foo>) {
//!     if let Some(value) = param.maybe() {
//!         do_something_with(value)
//!     } else {
//!         do_something_else()
//!     }
//! }
//! ```
//! This way you never need to write `foo(Some(x))`.

#![no_std]

pub trait Maybe<T>: Sized {
    fn maybe(self) -> Option<T>;
}

impl<T> Maybe<T> for T {
    fn maybe(self) -> Option<T> {
        Some(self)
    }
}

impl<T> Maybe<T> for Option<T> {
    fn maybe(self) -> Option<T> {
        self
    }
}