Add more funcs on Direction
This commit is contained in:
parent
c954484503
commit
cb2423ecb3
|
@ -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),
|
||||||
|
|
Loading…
Reference in New Issue