1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Placeholders for the unstable `fn_traits` feature.

/// Placeholder for [`FnOnce`]
pub trait SingleArgFnOnce<Arg>: FnOnce(Arg) -> <Self as SingleArgFnOnce<Arg>>::Output {
    /// The output type of the function.
    type Output;
}

impl<F, Arg, O> SingleArgFnOnce<Arg> for F
where
    F: FnOnce(Arg) -> O,
{
    type Output = O;
}

/// Placeholder for [`FnMut`]
pub trait SingleArgFnMut<Arg>:
    SingleArgFnOnce<Arg> + FnMut(Arg) -> <Self as SingleArgFnOnce<Arg>>::Output
{
}

impl<F, Arg, O> SingleArgFnMut<Arg> for F where F: FnMut(Arg) -> O {}

/// Placeholder for [`Fn`]
pub trait SingleArgFn<Arg>:
    SingleArgFnMut<Arg> + Fn(Arg) -> <Self as SingleArgFnOnce<Arg>>::Output
{
}

impl<F, Arg, O> SingleArgFn<Arg> for F where F: Fn(Arg) -> O {}

/// Used in cases that a function needs to return an [`Option`]
/// who's lifetime is tied to the input.
pub trait OptionTrait {
    /// The type of the item in the option.
    type Item;

    /// Converts `self` into an `Option`.
    fn into_option(self) -> Option<Self::Item>;
}

impl<T> OptionTrait for Option<T> {
    type Item = T;

    fn into_option(self) -> Option<Self::Item> {
        self
    }
}