changd get to return cow instead of rc
This commit is contained in:
13
src/lib.rs
13
src/lib.rs
@@ -1,17 +1,20 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::RwLock;
|
use std::sync::{RwLock, RwLockWriteGuard};
|
||||||
|
|
||||||
pub struct StateOwner {
|
pub struct StateOwner {
|
||||||
state: RwLock<Rc<String>>,
|
state: Rc<RwLock<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StateOwner {
|
impl StateOwner {
|
||||||
pub fn new(state: String) -> StateOwner {
|
pub fn new(state: String) -> StateOwner {
|
||||||
StateOwner { state: RwLock::new(Rc::new(state)) }
|
StateOwner { state: Rc::new(RwLock::new(state)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_state(&self) -> Rc<String> {
|
pub fn get_state(&self) -> Cow<str> {
|
||||||
self.state.read().unwrap().clone()
|
let ret = self.state.read().unwrap().clone();
|
||||||
|
|
||||||
|
Cow::from(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user