return rc instead of direct ref

This commit is contained in:
2024-09-07 15:39:07 -04:00
parent 5b5b749738
commit 426dbe8619

View File

@@ -1,14 +1,18 @@
use std::rc::Rc;
use std::sync::RwLock;
pub struct StateOwner { pub struct StateOwner {
state: String, state: RwLock<Rc<String>>,
} }
impl StateOwner { impl StateOwner {
pub fn new(state: String) -> StateOwner { pub fn new(state: String) -> StateOwner {
StateOwner { state } StateOwner { state: RwLock::new(Rc::new(state)) }
} }
pub fn get_state(&self) -> &str { pub fn get_state(&self) -> Rc<String> {
&self.state self.state.read().unwrap().clone()
} }
}
}