diff options
author | stale <redkugelblitzin@gmail.com> | 2022-07-01 20:53:11 -0300 |
---|---|---|
committer | stale <redkugelblitzin@gmail.com> | 2022-07-01 20:53:11 -0300 |
commit | fe851ee7ea31caa48a6d9a8ce1ddbb30854f2321 (patch) | |
tree | 27a5f19799d7c3ba654ea09ac3eb41ef7d9dfde0 /src/types.rs | |
parent | c68dc16bef476203a4424c4b857f16eeb8f0e119 (diff) |
more config options and a good refactoring
Diffstat (limited to 'src/types.rs')
-rw-r--r-- | src/types.rs | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/types.rs b/src/types.rs index f9f166a..7cdd44c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -14,17 +14,6 @@ use serde::Serialize; use crate::minesweeper; use crate::livepos; -#[derive(Debug, Clone)] -pub struct Config { - pub cert: String, - pub pkey: String, - pub index_pg: String, - pub room_pg: String, - pub client_code: String, - pub stylesheet: String, - pub socket_addr: SocketAddr, -} - #[derive(Debug, Serialize, Clone)] pub struct RoomConf { pub name: String, @@ -83,14 +72,19 @@ impl std::borrow::Borrow<str> for RoomId { } impl RoomId { - pub fn new_in<T>(map: &HashMap<RoomId, T>) -> Self { + pub fn new_among<'a, I>(existing: I) -> Self + where + I: IntoIterator<Item = &'a RoomId>, + <I as IntoIterator>::IntoIter: Clone, + { use rand::{ thread_rng, Rng, distributions::Alphanumeric }; let id = RoomId(thread_rng() .sample_iter(&Alphanumeric) .take(16) .map(char::from) .collect::<String>()); - if map.contains_key(&id) { RoomId::new_in(map) } + let existing = existing.into_iter(); + if existing.clone().any(|x| *x == id) { Self::new_among(existing) } else { id } } } |