Add more funcs on Direction

This commit is contained in:
Magnus Ulimoen 2020-09-04 00:12:47 +02:00
parent c954484503
commit cb2423ecb3
1 changed files with 16 additions and 0 deletions

View File

@ -21,6 +21,22 @@ pub struct Direction<T> {
} }
impl<T> Direction<T> { impl<T> Direction<T> {
pub fn as_ref(&self) -> Direction<&T> {
Direction {
north: &self.north,
south: &self.south,
west: &self.west,
east: &self.east,
}
}
pub fn as_mut(&mut self) -> Direction<&mut T> {
Direction {
north: &mut self.north,
south: &mut self.south,
west: &mut self.west,
east: &mut self.east,
}
}
pub fn map<U>(self, f: impl Fn(T) -> U) -> Direction<U> { pub fn map<U>(self, f: impl Fn(T) -> U) -> Direction<U> {
Direction { Direction {
north: f(self.north), north: f(self.north),