return rc instead of direct ref
This commit is contained in:
14
src/lib.rs
14
src/lib.rs
@@ -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()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user