diff --git a/src/main.rs b/src/main.rs index 4ab047f..76fccbb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,7 +59,7 @@ async fn main() { let view = view_port.outer().get_view(); let mut stream = view_port.outer().stream().map({ - move |_| view.read().unwrap().as_ref().unwrap().view(()).unwrap() + move |_| view.view(()).unwrap() }); let fut = task::spawn({ diff --git a/src/view.rs b/src/view.rs index 75ad91d..6b804c8 100644 --- a/src/view.rs +++ b/src/view.rs @@ -95,6 +95,63 @@ where T: Send + Sync, //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> +use std::ops::Deref; +use std::sync::{Arc, RwLock}; + +impl View for RwLock { + type Key = T::Key; + type Value = T::Value; + + fn view(&self, key: T::Key) -> Option { + self.read().unwrap().view(key) + } +} + +impl Observer for RwLock { + type Msg = T::Msg; + + fn notify(&self, msg: T::Msg) { + self.read().unwrap().notify(msg) + } +} + +impl View for Arc { + type Key = T::Key; + type Value = T::Value; + + fn view(&self, key: T::Key) -> Option { + self.deref().view(key) + } +} + +impl Observer for Arc { + type Msg = T::Msg; + + fn notify(&self, msg: T::Msg) { + self.deref().notify(msg) + } +} + +impl View for Arc> +where K: Send + Sync, + V: Send + Sync { + type Key = K; + type Value = V; + + fn view(&self, key: K) -> Option { + self.deref().view(key) + } +} + +impl Observer for Arc> +where T: Send + Sync { + type Msg = T; + + fn notify(&self, msg: T) { + self.deref().notify(msg) + } +} + impl View for Option { type Key = T::Key; type Value = T::Value; @@ -118,41 +175,3 @@ impl Observer for Option { } } -//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> - -impl View for std::sync::RwLock { - type Key = T::Key; - type Value = T::Value; - - fn view(&self, key: T::Key) -> Option { - self.read().unwrap().view(key) - } -} - -impl Observer for std::sync::RwLock { - type Msg = T::Msg; - - fn notify(&self, msg: T::Msg) { - self.read().unwrap().notify(msg) - } -} - -use std::ops::Deref; - -impl View for std::sync::Arc { - type Key = T::Key; - type Value = T::Value; - - fn view(&self, key: T::Key) -> Option { - self.deref().view(key) - } -} - -impl Observer for std::sync::Arc { - type Msg = T::Msg; - - fn notify(&self, msg: T::Msg) { - self.deref().notify(msg) - } -} -