use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq)]
#[serde(rename_all = "snake_case")]
pub struct AllowedDirections {
pub(crate) directions: Vec<String>,
}
impl AllowedDirections {
pub(crate) fn init() -> AllowedDirections {
let directions = [
"north", "south", "east", "west", "up", "down", "left", "right",
]
.iter()
.map(|s| s.to_string())
.collect();
AllowedDirections { directions }
}
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, Ord, PartialEq, PartialOrd)]
#[serde(rename_all = "snake_case")]
pub enum Directions {
#[serde(rename = "east")]
East,
#[serde(rename = "north")]
North,
#[serde(rename = "south")]
South,
#[serde(rename = "west")]
West,
#[serde(rename = "up")]
Up,
#[serde(rename = "down")]
Down,
}
impl std::fmt::Display for Directions {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
Directions::North => write!(f, "north"),
Directions::South => write!(f, "south"),
Directions::East => write!(f, "east"),
Directions::West => write!(f, "west"),
Directions::Up => write!(f, "up"),
Directions::Down => write!(f, "down"),
}
}
}