rstm_core/traits/
convert.rs

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
/*
    Appellation: convert <module>
    Contrib: FL03 <jo3mccain@icloud.com>
*/
use crate::Direction;

/// The [AsDirection] trait provides a convience method for converting a type into a [Direction].
pub trait AsDirection {
    fn as_direction(&self) -> Direction;
}
/// The [IntoDirection] trait provides a convience method for converting a type into a [Direction].
pub trait IntoDirection {
    fn into_direction(self) -> Direction;
}

/*
 ************* Implementations *************
*/
impl<T> AsDirection for T
where
    T: Clone + IntoDirection,
{
    fn as_direction(&self) -> Direction {
        self.clone().into_direction()
    }
}

impl<T> IntoDirection for T
where
    T: Into<Direction>,
{
    fn into_direction(self) -> Direction {
        self.into()
    }
}