unflatten 0.1.1

Extension for un-flattening `Option<T>`.
Documentation
//! # unflatten
//!
//! `unflatten` is a <sup>[joke of a]</sup> library which provides one thing:
//!
//! ```rust
//! use unflatten::Unflatten;
//!
//! let option = Some("body once told me");
//! let unflattened = option.unflatten();
//!
//! assert_eq!(unflattened, Some(Some("body once told me")));
//! ```
//!
#![no_std]

mod sealed {
    pub trait Sealed {}
}

use sealed::Sealed;

pub trait Unflatten: Sealed + Sized {
    fn unflatten(self) -> Option<Self> {
        Some(self)
    }
}

impl<T>    Sealed for Option<T> {}
impl<T> Unflatten for Option<T> {}

#[cfg(test)]
mod tests {
    use super::Unflatten;

    #[test]
    fn unflattening_some_works() {
        let x: Option<i32> = Some(1);

        assert_eq!(x.unflatten(), Some(Some(1)));
    }

    #[test]
    fn unflattening_none_works() {
        let x: Option<i32> = None;

        assert_eq!(x.unflatten(), Some(None));
    }

    #[test]
    fn flattening_unflattened_some_returns_same() {
        let x: Option<i32> = Some(1);

        assert_eq!(x.unflatten().flatten(), x);
    }

    #[test]
    fn flattening_unflattened_none_returns_same() {
        let x: Option<i32> = None;

        assert_eq!(x.unflatten().flatten(), x);
    }

    #[test]
    fn unflattening_flattened_some_returns_same() {
        let x: Option<Option<i32>> = Some(Some(1));

        assert_eq!(x.flatten().unflatten(), x);
    }
}