common/rust: derive Enum for vec2::Direction

This commit is contained in:
Xiretza 2023-12-18 18:22:48 +00:00
parent 839b787de2
commit b9cda61f6d
3 changed files with 5 additions and 1 deletions

1
Cargo.lock generated
View file

@ -15,6 +15,7 @@ dependencies = [
name = "aoc"
version = "0.1.0"
dependencies = [
"enum-map",
"num-traits",
"strum 0.24.1",
"thiserror",

View file

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
enum-map = "2.7.3"
num-traits = "0.2.15"
strum = { version = "0.24.1", features = ["derive"] }
thiserror = "1.0.38"

View file

@ -4,6 +4,8 @@ use std::{
str::FromStr,
};
use enum_map::Enum;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Vec2 {
pub x: i32, // increases toward right
@ -169,7 +171,7 @@ impl From<Direction> for Vec2 {
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Enum)]
pub enum Direction {
Up,
Down,