From fe851ee7ea31caa48a6d9a8ce1ddbb30854f2321 Mon Sep 17 00:00:00 2001 From: stale Date: Fri, 1 Jul 2022 20:53:11 -0300 Subject: more config options and a good refactoring --- src/types.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src/types.rs') 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 for RoomId { } impl RoomId { - pub fn new_in(map: &HashMap) -> Self { + pub fn new_among<'a, I>(existing: I) -> Self + where + I: IntoIterator, + ::IntoIter: Clone, + { use rand::{ thread_rng, Rng, distributions::Alphanumeric }; let id = RoomId(thread_rng() .sample_iter(&Alphanumeric) .take(16) .map(char::from) .collect::()); - 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 } } } -- cgit v1.2.3