diff options
| author | troido <troido@protonmail.com> | 2020-09-24 22:18:30 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-09-24 22:18:30 +0200 |
| commit | 9eb3a9da97e53cee14e585e027badb3783b8e25e (patch) | |
| tree | 4840bc49cbde975289b3e3b663967a368b444f8b /src/roomid.rs | |
| parent | 13b53f3e89bcd6d33a534403162d1b09502bec70 (diff) | |
turned sprite, playerid and roomid into tuple structs
Diffstat (limited to 'src/roomid.rs')
| -rw-r--r-- | src/roomid.rs | 24 |
1 files changed, 12 insertions, 12 deletions
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) + } +} |
