From fffb23cd12ed25c1a3ffcd632e8b99b5ec3a6dbc Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 17 Jan 2021 11:17:59 +0100 Subject: [PATCH] add to_sequence() in ViewPort --- src/main.rs | 8 +++----- src/sequence/vec_buffer.rs | 12 +++++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7b858a4..076bd31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,11 +78,9 @@ async fn main() { let vec_port = ViewPort::new(); let mut vec_buf = sequence::VecBuffer::::new(vec_port.inner()); - // project Vec-Buffer to SequenceView - let vec_seq_port = ViewPort::new(); - let vec_seq = sequence::VecSequence::new(vec_seq_port.inner()); - vec_port.add_observer(vec_seq.clone()); - let vec_term_view = vec_seq_port.outer() + // project Vec-Buffer + let vec_term_view = vec_port.outer() + .to_sequence() .to_index() .map_key( |idx: &usize| Point2::::new(*idx as i16, 0), diff --git a/src/sequence/vec_buffer.rs b/src/sequence/vec_buffer.rs index ce6cd6f..a1c75e7 100644 --- a/src/sequence/vec_buffer.rs +++ b/src/sequence/vec_buffer.rs @@ -3,7 +3,7 @@ use { sync::{Arc, RwLock} }, crate::{ - core::{View, Observer, ObserverExt, ObserverBroadcast, InnerViewPort}, + core::{View, Observer, ObserverExt, ObserverBroadcast, ViewPort, InnerViewPort, OuterViewPort}, sequence::SequenceView, } }; @@ -31,6 +31,16 @@ where T: Clone + Send + Sync + 'static { cast: Arc>>> } +impl OuterViewPort>> +where T: Clone + Send + Sync + 'static { + pub fn to_sequence(&self) -> OuterViewPort> { + let port = ViewPort::new(); + let vec_seq = VecSequence::new(port.inner()); + self.add_observer(vec_seq.clone()); + port.into_outer() + } +} + impl VecSequence where T: Clone + Send + Sync + 'static { pub fn new(