diff options
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) + } +} |
