summaryrefslogtreecommitdiff
path: root/src/roomid.rs
blob: 22ca88bf82fc69027da4fab4c979b261d455ce74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

use std::fmt;
use std::collections::HashMap;
use serde::{Serialize, Deserialize};

#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize)]
pub struct RoomId(pub String);

impl RoomId {
	pub fn format(&self, dict: HashMap<&str, &str>) -> Self {
		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)
	}
}