From f8b5da1393a5d30cc1a4ac13da45756a330eb25e Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 16 May 2021 23:47:17 +0200 Subject: [PATCH] port: rename observers to cast --- nested/src/core/port.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/nested/src/core/port.rs b/nested/src/core/port.rs index ebfe35f..9e871aa 100644 --- a/nested/src/core/port.rs +++ b/nested/src/core/port.rs @@ -18,14 +18,14 @@ use { \*/ pub struct ViewPort { view: Arc>>>, - observers: Arc>> + cast: Arc>> } impl ViewPort { pub fn new() -> Self { ViewPort { view: Arc::new(RwLock::new(None)), - observers: Arc::new(RwLock::new(ObserverBroadcast::new())) + cast: Arc::new(RwLock::new(ObserverBroadcast::new())) } } @@ -37,28 +37,28 @@ impl ViewPort { pub fn set_view(&self, view: Option>) { *self.view.write().unwrap() = view.clone(); - self.observers.write().unwrap().reset(view); + self.cast.write().unwrap().reset(view); } pub fn add_observer(&self, observer: Arc>>) { - self.observers.write().unwrap().add_observer(Arc::downgrade(&observer)); + self.cast.write().unwrap().add_observer(Arc::downgrade(&observer)); observer.write().unwrap().reset(self.view.read().unwrap().clone()); } pub fn inner(&self) -> InnerViewPort { - InnerViewPort(ViewPort{ view: self.view.clone(), observers: self.observers.clone() }) + InnerViewPort(ViewPort{ view: self.view.clone(), cast: self.cast.clone() }) } pub fn outer(&self) -> OuterViewPort { - OuterViewPort(ViewPort{ view: self.view.clone(), observers: self.observers.clone() }) + OuterViewPort(ViewPort{ view: self.view.clone(), cast: self.cast.clone() }) } pub fn into_inner(self) -> InnerViewPort { - InnerViewPort(ViewPort{ view: self.view, observers: self.observers }) + InnerViewPort(ViewPort{ view: self.view, cast: self.cast }) } pub fn into_outer(self) -> OuterViewPort { - OuterViewPort(ViewPort{ view: self.view, observers: self.observers }) + OuterViewPort(ViewPort{ view: self.view, cast: self.cast }) } } @@ -66,7 +66,7 @@ impl Clone for ViewPort { fn clone(&self) -> Self { ViewPort { view: self.view.clone(), - observers: self.observers.clone() + cast: self.cast.clone() } } } @@ -80,7 +80,7 @@ pub struct OuterViewPort(ViewPort); impl InnerViewPort { pub fn get_broadcast(&self) -> Arc>> { - self.0.observers.clone() + self.0.cast.clone() } pub fn set_view(&self, view: Option>) -> Arc>> { @@ -93,7 +93,7 @@ impl InnerViewPort { } pub fn notify(&self, msg: &V::Msg) { - self.0.observers.read().unwrap().notify(msg); + self.0.cast.read().unwrap().notify(msg); } } @@ -163,16 +163,16 @@ where V::Msg: Clone { #[derive(Debug, Clone)] pub struct AnyViewPort { view: Arc, - observers: Arc + cast: Arc } impl AnyViewPort { pub fn downcast(self) -> Result, AnyViewPort> { match ( self.view.clone().downcast::>>>(), - self.observers.clone().downcast::>>() + self.cast.clone().downcast::>>() ) { - (Ok(view), Ok(observers)) => Ok(ViewPort{view, observers}), + (Ok(view), Ok(cast)) => Ok(ViewPort{view, cast}), _ => Err(self) } } @@ -182,7 +182,7 @@ impl From> for AnyViewPort { fn from(port: ViewPort) -> Self { AnyViewPort { view: port.view as Arc, - observers: port.observers as Arc + cast: port.cast as Arc } } } @@ -205,7 +205,7 @@ impl From> for AnyOuterViewPort { fn from(port: OuterViewPort) -> Self { AnyOuterViewPort(AnyViewPort{ view: port.0.view as Arc, - observers: port.0.observers as Arc + cast: port.0.cast as Arc }) } } @@ -220,7 +220,7 @@ impl From> for AnyInnerViewPort { fn from(port: InnerViewPort) -> Self { AnyInnerViewPort(AnyViewPort{ view: port.0.view as Arc, - observers: port.0.observers as Arc + cast: port.0.cast as Arc }) } }