stefans-utils 0.2.1

A collection of useful Rust utility functions, types, and traits.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pub trait MapInto<T> {
    fn map_into(self) -> T;
}

impl<A: Into<B>, B> MapInto<Option<B>> for Option<A> {
    fn map_into(self) -> Option<B> {
        self.map(A::into)
    }
}

impl<OkA: Into<OkB>, ErrA: Into<ErrB>, OkB, ErrB> MapInto<Result<OkB, ErrB>> for Result<OkA, ErrA> {
    fn map_into(self) -> Result<OkB, ErrB> {
        match self {
            Ok(a) => Ok(a.into()),
            Err(err_a) => Err(err_a.into()),
        }
    }
}