From 2da96c54823d14b22f16f11d9963065913807312 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Mon, 7 Dec 2020 18:28:28 +0100 Subject: [PATCH] add impls for Arc and Arc --- src/main.rs | 2 +- src/view.rs | 95 ++++++++++++++++++++++++++++++++--------------------- 2 files changed, 58 insertions(+), 39 deletions(-) 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) - } -} -