add to_sequence() in ViewPort<Vec>

This commit is contained in:
Michael Sippel 2021-01-17 11:17:59 +01:00
parent 4fceafcac4
commit fffb23cd12
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 14 additions and 6 deletions

View file

@ -78,11 +78,9 @@ async fn main() {
let vec_port = ViewPort::new();
let mut vec_buf = sequence::VecBuffer::<char>::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::<i16>::new(*idx as i16, 0),

View file

@ -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<RwLock<ObserverBroadcast<dyn SequenceView<Item = T>>>>
}
impl<T> OuterViewPort<RwLock<Vec<T>>>
where T: Clone + Send + Sync + 'static {
pub fn to_sequence(&self) -> OuterViewPort<dyn SequenceView<Item = T>> {
let port = ViewPort::new();
let vec_seq = VecSequence::new(port.inner());
self.add_observer(vec_seq.clone());
port.into_outer()
}
}
impl<T> VecSequence<T>
where T: Clone + Send + Sync + 'static {
pub fn new(