From 9eb3a9da97e53cee14e585e027badb3783b8e25e Mon Sep 17 00:00:00 2001 From: troido Date: Thu, 24 Sep 2020 22:18:30 +0200 Subject: turned sprite, playerid and roomid into tuple structs --- src/roomid.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/roomid.rs') diff --git a/src/roomid.rs b/src/roomid.rs index d3c0b17..22ca88b 100644 --- a/src/roomid.rs +++ b/src/roomid.rs @@ -1,21 +1,21 @@ +use std::fmt; use std::collections::HashMap; +use serde::{Serialize, Deserialize}; -#[derive(Debug, PartialEq, Eq, Clone, Hash)] -pub struct RoomId { - pub name: String -} +#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)] +pub struct RoomId(pub String); impl RoomId { - pub fn from_str(name: &str) -> Self { - Self {name: name.to_string()} - } - pub fn to_string(&self) -> String { - self.name.clone() - } pub fn format(&self, dict: HashMap<&str, &str>) -> Self { - let name = dict.into_iter().fold(self.name.clone(), |name, (from, to)| name.replace(from, to)); - Self {name} + let name = dict.into_iter().fold(self.0.clone(), |name, (from, to)| name.replace(from, to)); + Self(name) } } + +impl fmt::Display for RoomId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} -- cgit