WIP
This commit is contained in:
@@ -12,6 +12,8 @@ pub mod bincode {
|
||||
pub use bincode::*;
|
||||
}
|
||||
|
||||
pub use futures_util;
|
||||
|
||||
use collect_s::Collectable;
|
||||
use container::ByteEstimate;
|
||||
use netpod::range::evrange::SeriesRange;
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
use crate::collect_s::Collected;
|
||||
use crate::streamitem::RangeCompletableItem;
|
||||
use crate::streamitem::Sitemty;
|
||||
use crate::streamitem::StreamItem;
|
||||
use crate::Events;
|
||||
use err::Error;
|
||||
use futures_util::stream;
|
||||
use futures_util::Future;
|
||||
use futures_util::Stream;
|
||||
use std::pin::Pin;
|
||||
|
||||
pub struct TransformProperties {
|
||||
@@ -6,8 +14,29 @@ pub struct TransformProperties {
|
||||
pub needs_value: bool,
|
||||
}
|
||||
|
||||
pub trait EventTransform {
|
||||
pub trait WithTransformProperties {
|
||||
fn query_transform_properties(&self) -> TransformProperties;
|
||||
}
|
||||
|
||||
impl<T> WithTransformProperties for Box<T>
|
||||
where
|
||||
T: WithTransformProperties,
|
||||
{
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
self.as_ref().query_transform_properties()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> WithTransformProperties for Pin<Box<T>>
|
||||
where
|
||||
T: WithTransformProperties,
|
||||
{
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
self.as_ref().query_transform_properties()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait EventTransform: WithTransformProperties {
|
||||
fn transform(&mut self, src: Box<dyn Events>) -> Box<dyn Events>;
|
||||
}
|
||||
|
||||
@@ -15,12 +44,8 @@ impl<T> EventTransform for Box<T>
|
||||
where
|
||||
T: EventTransform,
|
||||
{
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
self.as_ref().query_transform_properties()
|
||||
}
|
||||
|
||||
fn transform(&mut self, src: Box<dyn Events>) -> Box<dyn Events> {
|
||||
todo!()
|
||||
self.as_mut().transform(src)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,10 +53,6 @@ impl<T> EventTransform for Pin<Box<T>>
|
||||
where
|
||||
T: EventTransform,
|
||||
{
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
self.as_ref().query_transform_properties()
|
||||
}
|
||||
|
||||
fn transform(&mut self, src: Box<dyn Events>) -> Box<dyn Events> {
|
||||
todo!()
|
||||
}
|
||||
@@ -45,12 +66,57 @@ impl IdentityTransform {
|
||||
}
|
||||
}
|
||||
|
||||
impl EventTransform for IdentityTransform {
|
||||
fn transform(&mut self, src: Box<dyn Events>) -> Box<dyn Events> {
|
||||
src
|
||||
}
|
||||
|
||||
impl WithTransformProperties for IdentityTransform {
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl EventTransform for IdentityTransform {
|
||||
fn transform(&mut self, src: Box<dyn Events>) -> Box<dyn Events> {
|
||||
src
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TransformEvent(pub Box<dyn EventTransform>);
|
||||
|
||||
impl WithTransformProperties for TransformEvent {
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
self.0.query_transform_properties()
|
||||
}
|
||||
}
|
||||
|
||||
impl EventTransform for TransformEvent {
|
||||
fn transform(&mut self, src: Box<dyn Events>) -> Box<dyn Events> {
|
||||
self.0.transform(src)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EventStream(pub Pin<Box<dyn Stream<Item = Sitemty<Box<dyn Events>>> + Send>>);
|
||||
|
||||
impl<T> From<T> for EventStream
|
||||
where
|
||||
T: Events,
|
||||
{
|
||||
fn from(value: T) -> Self {
|
||||
let item = Ok(StreamItem::DataItem(RangeCompletableItem::Data(Box::new(value) as _)));
|
||||
let x = stream::iter(vec![item]);
|
||||
EventStream(Box::pin(x))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO these must return type which can take events as input.
|
||||
|
||||
pub struct TransformedCollectedStream(pub Pin<Box<dyn Future<Output = Result<Box<dyn Collected>, Error>>>>);
|
||||
|
||||
impl WithTransformProperties for TransformedCollectedStream {
|
||||
fn query_transform_properties(&self) -> TransformProperties {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl EventTransform for TransformedCollectedStream {
|
||||
fn transform(&mut self, src: Box<dyn Events>) -> Box<dyn Events> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user