changd get to return cow instead of rc

This commit is contained in:
2024-09-07 16:06:27 -04:00
parent 426dbe8619
commit 3742ffbeb1

View File

@@ -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)
} }