Implement conversion from parse to runtime

This commit is contained in:
2020-09-03 23:43:51 +02:00
parent d0e6727ac3
commit 7ca3d1fda2
2 changed files with 186 additions and 18 deletions

View File

@@ -12,7 +12,7 @@ pub use kronecker_product::kronecker_product;
use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug)]
#[derive(Copy, Clone, Debug, Default)]
pub struct Direction<T> {
pub north: T,
pub south: T,
@@ -20,6 +20,17 @@ pub struct Direction<T> {
pub east: T,
}
impl<T> Direction<T> {
pub fn map<U>(self, f: impl Fn(T) -> U) -> Direction<U> {
Direction {
north: f(self.north),
south: f(self.south),
west: f(self.west),
east: f(self.east),
}
}
}
impl<T> Direction<T> {
pub fn north(&self) -> &T {
&self.north