From 720bb2e4f53d4467832ba59f97c9b6b6786181e7 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 20 Jun 2024 01:38:00 +0200 Subject: type safe indecies --- server/src/protocol.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'server/src/protocol.rs') diff --git a/server/src/protocol.rs b/server/src/protocol.rs index 24fe2468..a629ffbf 100644 --- a/server/src/protocol.rs +++ b/server/src/protocol.rs @@ -2,11 +2,22 @@ use crate::data::Gamedata; use glam::{IVec2, Vec2}; use serde::{Deserialize, Serialize}; -pub type PlayerID = i64; -pub type ItemIndex = usize; -pub type TileIndex = usize; -pub type RecipeIndex = usize; -pub type DemandIndex = usize; +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[serde(transparent)] +pub struct PlayerID(pub i64); + +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[serde(transparent)] +pub struct ItemIndex(pub usize); +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[serde(transparent)] +pub struct TileIndex(pub usize); +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[serde(transparent)] +pub struct RecipeIndex(pub usize); +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[serde(transparent)] +pub struct DemandIndex(pub usize); #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "snake_case", tag = "type")] -- cgit v1.2.3-70-g09d2