diff --git a/src/states.rs b/src/states.rs index e809185..37c6171 100644 --- a/src/states.rs +++ b/src/states.rs @@ -159,7 +159,7 @@ impl<'a, T: TopLevelGui + 'static> From for CreationType<'a> { pub struct States { gui_handler: Arc, - states: Mutex>>, + states: HashMap>, current_state: Mutex>>, control_top_gui: AtomicBool, @@ -173,7 +173,7 @@ impl States { Ok(States { gui_handler, - states: Mutex::new(HashMap::new()), + states: HashMap::new(), current_state: Mutex::new(None), control_top_gui: AtomicBool::new(true), @@ -193,11 +193,11 @@ impl States { /// Adds a single state pub fn add_state<'a>( - &self, + &mut self, id: &str, creation_type: impl Into>, ) -> Result<()> { - self.states.lock().unwrap().insert( + self.states.insert( id.to_string(), State::new(&self.gui_handler, id, creation_type.into())?, ); @@ -274,9 +274,7 @@ impl States { } fn get_state(&self, id: &str) -> Result> { - let states = self.states.lock().unwrap(); - - match states.get(id) { + match self.states.get(id) { Some(state) => Ok(state.clone()), None => Err(anyhow::Error::msg(format!("UiState not found: {}", id))), }