obrewin-utils 0.0.5

General utilities for Obrewin
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/// Convenient trait to convert to `Option<T>`.
/// `IntoOption<T> for F` is automatically implemented
/// if `TryInto<T> for F` is implemented.
pub trait IntoOption<T> {
    fn into_option(self) -> Option<T>;
}

impl<T, F> IntoOption<T> for F
where
    T: TryFrom<F>,
{
    fn into_option(self) -> Option<T> {
        self.try_into().ok()
    }
}