WIP typechecks and basic run
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::container::ByteEstimate;
|
||||
use crate::timebin::BinningggContainerBinsDyn;
|
||||
use crate::timebin::TimeBinned;
|
||||
use crate::AsAnyMut;
|
||||
use crate::AsAnyRef;
|
||||
@@ -19,13 +20,10 @@ pub trait ToJsonBytes {
|
||||
fn to_json_bytes(&self) -> Result<Vec<u8>, Error>;
|
||||
}
|
||||
|
||||
// TODO check usage of this trait
|
||||
pub trait ToJsonResult: erased_serde::Serialize + fmt::Debug + AsAnyRef + AsAnyMut + Send {
|
||||
fn to_json_result(&self) -> Result<Box<dyn ToJsonBytes>, Error>;
|
||||
pub trait ToJsonResult: fmt::Debug + AsAnyRef + AsAnyMut + Send {
|
||||
fn to_json_value(&self) -> Result<serde_json::Value, Error>;
|
||||
}
|
||||
|
||||
erased_serde::serialize_trait_object!(ToJsonResult);
|
||||
|
||||
impl AsAnyRef for serde_json::Value {
|
||||
fn as_any_ref(&self) -> &dyn Any {
|
||||
self
|
||||
@@ -39,8 +37,8 @@ impl AsAnyMut for serde_json::Value {
|
||||
}
|
||||
|
||||
impl ToJsonResult for serde_json::Value {
|
||||
fn to_json_result(&self) -> Result<Box<dyn ToJsonBytes>, Error> {
|
||||
Ok(Box::new(self.clone()))
|
||||
fn to_json_value(&self) -> Result<serde_json::Value, Error> {
|
||||
Ok(self.clone())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,34 +48,31 @@ impl ToJsonBytes for serde_json::Value {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Collected: fmt::Debug + TypeName + Send + AsAnyRef + WithLen + ToJsonResult {}
|
||||
pub trait CollectedDyn: fmt::Debug + TypeName + Send + AsAnyRef + WithLen + ToJsonResult {}
|
||||
|
||||
erased_serde::serialize_trait_object!(Collected);
|
||||
|
||||
impl ToJsonResult for Box<dyn Collected> {
|
||||
fn to_json_result(&self) -> Result<Box<dyn ToJsonBytes>, Error> {
|
||||
self.as_ref().to_json_result()
|
||||
impl ToJsonResult for Box<dyn CollectedDyn> {
|
||||
fn to_json_value(&self) -> Result<serde_json::Value, Error> {
|
||||
ToJsonResult::to_json_value(self.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl WithLen for Box<dyn Collected> {
|
||||
impl WithLen for Box<dyn CollectedDyn> {
|
||||
fn len(&self) -> usize {
|
||||
self.as_ref().len()
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeName for Box<dyn Collected> {
|
||||
impl TypeName for Box<dyn CollectedDyn> {
|
||||
fn type_name(&self) -> String {
|
||||
self.as_ref().type_name()
|
||||
}
|
||||
}
|
||||
|
||||
impl Collected for Box<dyn Collected> {}
|
||||
impl CollectedDyn for Box<dyn CollectedDyn> {}
|
||||
|
||||
// TODO rename to `Typed`
|
||||
pub trait CollectorType: fmt::Debug + Send + Unpin + WithLen + ByteEstimate {
|
||||
type Input: Collectable;
|
||||
type Output: Collected + ToJsonResult + Serialize;
|
||||
pub trait CollectorTy: fmt::Debug + Send + Unpin + WithLen + ByteEstimate {
|
||||
type Input: CollectableDyn;
|
||||
type Output: CollectedDyn + ToJsonResult + Serialize;
|
||||
|
||||
fn ingest(&mut self, src: &mut Self::Input);
|
||||
fn set_range_complete(&mut self);
|
||||
@@ -88,8 +83,8 @@ pub trait CollectorType: fmt::Debug + Send + Unpin + WithLen + ByteEstimate {
|
||||
fn result(&mut self, range: Option<SeriesRange>, binrange: Option<BinnedRangeEnum>) -> Result<Self::Output, Error>;
|
||||
}
|
||||
|
||||
pub trait Collector: fmt::Debug + Send + WithLen + ByteEstimate {
|
||||
fn ingest(&mut self, src: &mut dyn Collectable);
|
||||
pub trait CollectorDyn: fmt::Debug + Send + WithLen + ByteEstimate {
|
||||
fn ingest(&mut self, src: &mut dyn CollectableDyn);
|
||||
fn set_range_complete(&mut self);
|
||||
fn set_timed_out(&mut self);
|
||||
fn set_continue_at_here(&mut self);
|
||||
@@ -98,26 +93,26 @@ pub trait Collector: fmt::Debug + Send + WithLen + ByteEstimate {
|
||||
&mut self,
|
||||
range: Option<SeriesRange>,
|
||||
binrange: Option<BinnedRangeEnum>,
|
||||
) -> Result<Box<dyn Collected>, Error>;
|
||||
) -> Result<Box<dyn CollectedDyn>, Error>;
|
||||
}
|
||||
|
||||
impl<T> Collector for T
|
||||
impl<T> CollectorDyn for T
|
||||
where
|
||||
T: fmt::Debug + CollectorType + 'static,
|
||||
T: fmt::Debug + CollectorTy + 'static,
|
||||
{
|
||||
fn ingest(&mut self, src: &mut dyn Collectable) {
|
||||
if let Some(src) = src.as_any_mut().downcast_mut::<<T as CollectorType>::Input>() {
|
||||
fn ingest(&mut self, src: &mut dyn CollectableDyn) {
|
||||
if let Some(src) = src.as_any_mut().downcast_mut::<<T as CollectorTy>::Input>() {
|
||||
trace!("sees incoming &mut ref");
|
||||
T::ingest(self, src)
|
||||
} else {
|
||||
if let Some(src) = src.as_any_mut().downcast_mut::<Box<<T as CollectorType>::Input>>() {
|
||||
if let Some(src) = src.as_any_mut().downcast_mut::<Box<<T as CollectorTy>::Input>>() {
|
||||
trace!("sees incoming &mut Box");
|
||||
T::ingest(self, src)
|
||||
} else {
|
||||
error!(
|
||||
"No idea what this is. Expect: {} input {} got: {} {:?}",
|
||||
any::type_name::<T>(),
|
||||
any::type_name::<<T as CollectorType>::Input>(),
|
||||
any::type_name::<<T as CollectorTy>::Input>(),
|
||||
src.type_name(),
|
||||
src
|
||||
);
|
||||
@@ -141,7 +136,7 @@ where
|
||||
&mut self,
|
||||
range: Option<SeriesRange>,
|
||||
binrange: Option<BinnedRangeEnum>,
|
||||
) -> Result<Box<dyn Collected>, Error> {
|
||||
) -> Result<Box<dyn CollectedDyn>, Error> {
|
||||
let ret = T::result(self, range, binrange)?;
|
||||
Ok(Box::new(ret))
|
||||
}
|
||||
@@ -149,12 +144,73 @@ where
|
||||
|
||||
// TODO rename to `Typed`
|
||||
pub trait CollectableType: fmt::Debug + WithLen + AsAnyRef + AsAnyMut + TypeName + Send {
|
||||
type Collector: CollectorType<Input = Self>;
|
||||
type Collector: CollectorTy<Input = Self>;
|
||||
fn new_collector() -> Self::Collector;
|
||||
}
|
||||
|
||||
pub trait Collectable: fmt::Debug + WithLen + AsAnyRef + AsAnyMut + TypeName + Send {
|
||||
fn new_collector(&self) -> Box<dyn Collector>;
|
||||
#[derive(Debug)]
|
||||
pub struct CollectorForDyn {
|
||||
inner: Box<dyn CollectorDyn>,
|
||||
}
|
||||
|
||||
impl WithLen for CollectorForDyn {
|
||||
fn len(&self) -> usize {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl ByteEstimate for CollectorForDyn {
|
||||
fn byte_estimate(&self) -> u64 {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl CollectorDyn for CollectorForDyn {
|
||||
fn ingest(&mut self, src: &mut dyn CollectableDyn) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_range_complete(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_timed_out(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn set_continue_at_here(&mut self) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn result(
|
||||
&mut self,
|
||||
range: Option<SeriesRange>,
|
||||
binrange: Option<BinnedRangeEnum>,
|
||||
) -> Result<Box<dyn crate::collect_s::CollectedDyn>, Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CollectableDyn: fmt::Debug + WithLen + AsAnyRef + AsAnyMut + TypeName + Send {
|
||||
fn new_collector(&self) -> Box<dyn CollectorDyn>;
|
||||
}
|
||||
|
||||
impl TypeName for Box<dyn BinningggContainerBinsDyn> {
|
||||
fn type_name(&self) -> String {
|
||||
BinningggContainerBinsDyn::type_name(self.as_ref()).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl WithLen for Box<dyn BinningggContainerBinsDyn> {
|
||||
fn len(&self) -> usize {
|
||||
WithLen::len(self.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
impl CollectableDyn for Box<dyn BinningggContainerBinsDyn> {
|
||||
fn new_collector(&self) -> Box<dyn CollectorDyn> {
|
||||
self.as_ref().new_collector()
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeName for Box<dyn Events> {
|
||||
@@ -163,38 +219,38 @@ impl TypeName for Box<dyn Events> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Collectable for Box<dyn Events> {
|
||||
fn new_collector(&self) -> Box<dyn Collector> {
|
||||
impl CollectableDyn for Box<dyn Events> {
|
||||
fn new_collector(&self) -> Box<dyn CollectorDyn> {
|
||||
self.as_ref().new_collector()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Collectable for T
|
||||
impl<T> CollectableDyn for T
|
||||
where
|
||||
T: CollectableType + 'static,
|
||||
{
|
||||
fn new_collector(&self) -> Box<dyn Collector> {
|
||||
fn new_collector(&self) -> Box<dyn CollectorDyn> {
|
||||
Box::new(T::new_collector())
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeName for Box<dyn Collectable> {
|
||||
impl TypeName for Box<dyn CollectableDyn> {
|
||||
fn type_name(&self) -> String {
|
||||
self.as_ref().type_name()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO do this with some blanket impl:
|
||||
impl WithLen for Box<dyn Collectable> {
|
||||
impl WithLen for Box<dyn CollectableDyn> {
|
||||
fn len(&self) -> usize {
|
||||
WithLen::len(self.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
// TODO do this with some blanket impl:
|
||||
impl Collectable for Box<dyn Collectable> {
|
||||
fn new_collector(&self) -> Box<dyn Collector> {
|
||||
Collectable::new_collector(self.as_ref())
|
||||
impl CollectableDyn for Box<dyn CollectableDyn> {
|
||||
fn new_collector(&self) -> Box<dyn CollectorDyn> {
|
||||
CollectableDyn::new_collector(self.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,8 +266,8 @@ impl TypeName for Box<dyn TimeBinned> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Collectable for Box<dyn TimeBinned> {
|
||||
fn new_collector(&self) -> Box<dyn Collector> {
|
||||
impl CollectableDyn for Box<dyn TimeBinned> {
|
||||
fn new_collector(&self) -> Box<dyn CollectorDyn> {
|
||||
self.as_ref().new_collector()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ pub mod bincode {
|
||||
|
||||
pub use futures_util;
|
||||
|
||||
use collect_s::Collectable;
|
||||
use collect_s::CollectableDyn;
|
||||
use container::ByteEstimate;
|
||||
use std::any::Any;
|
||||
use std::collections::VecDeque;
|
||||
@@ -122,7 +122,7 @@ pub trait Events:
|
||||
fmt::Debug
|
||||
+ TypeName
|
||||
+ Any
|
||||
+ Collectable
|
||||
+ CollectableDyn
|
||||
+ TimeBinnable
|
||||
+ WithLen
|
||||
+ ByteEstimate
|
||||
@@ -134,9 +134,9 @@ pub trait Events:
|
||||
fn as_time_binnable_mut(&mut self) -> &mut dyn TimeBinnable;
|
||||
fn verify(&self) -> bool;
|
||||
fn output_info(&self) -> String;
|
||||
fn as_collectable_mut(&mut self) -> &mut dyn Collectable;
|
||||
fn as_collectable_with_default_ref(&self) -> &dyn Collectable;
|
||||
fn as_collectable_with_default_mut(&mut self) -> &mut dyn Collectable;
|
||||
fn as_collectable_mut(&mut self) -> &mut dyn CollectableDyn;
|
||||
fn as_collectable_with_default_ref(&self) -> &dyn CollectableDyn;
|
||||
fn as_collectable_with_default_mut(&mut self) -> &mut dyn CollectableDyn;
|
||||
fn ts_min(&self) -> Option<u64>;
|
||||
fn ts_max(&self) -> Option<u64>;
|
||||
// TODO is this used?
|
||||
@@ -204,15 +204,15 @@ impl Events for Box<dyn Events> {
|
||||
Events::output_info(self.as_ref())
|
||||
}
|
||||
|
||||
fn as_collectable_mut(&mut self) -> &mut dyn Collectable {
|
||||
fn as_collectable_mut(&mut self) -> &mut dyn CollectableDyn {
|
||||
Events::as_collectable_mut(self.as_mut())
|
||||
}
|
||||
|
||||
fn as_collectable_with_default_ref(&self) -> &dyn Collectable {
|
||||
fn as_collectable_with_default_ref(&self) -> &dyn CollectableDyn {
|
||||
Events::as_collectable_with_default_ref(self.as_ref())
|
||||
}
|
||||
|
||||
fn as_collectable_with_default_mut(&mut self) -> &mut dyn Collectable {
|
||||
fn as_collectable_with_default_mut(&mut self) -> &mut dyn CollectableDyn {
|
||||
Events::as_collectable_with_default_mut(self.as_mut())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
pub mod timebinimpl;
|
||||
|
||||
use crate::collect_s::Collectable;
|
||||
use crate::collect_s::Collector;
|
||||
use crate::collect_s::CollectableDyn;
|
||||
use crate::collect_s::CollectorDyn;
|
||||
use crate::collect_s::ToJsonResult;
|
||||
use crate::container::ByteEstimate;
|
||||
use crate::overlap::RangeOverlapInfo;
|
||||
use crate::vecpreview::PreviewRange;
|
||||
use crate::AsAnyMut;
|
||||
@@ -103,7 +104,7 @@ pub trait BinningggContainerEventsDyn: fmt::Debug + Send {
|
||||
fn to_anybox(&mut self) -> Box<dyn std::any::Any>;
|
||||
}
|
||||
|
||||
pub trait BinningggContainerBinsDyn: fmt::Debug + Send + fmt::Display + WithLen + AsAnyMut + Collectable {
|
||||
pub trait BinningggContainerBinsDyn: fmt::Debug + Send + fmt::Display + WithLen + AsAnyMut + CollectableDyn {
|
||||
fn type_name(&self) -> &'static str;
|
||||
fn empty(&self) -> BinsBoxed;
|
||||
fn clone(&self) -> BinsBoxed;
|
||||
@@ -147,11 +148,11 @@ pub trait BinnedEventsTimeweightTrait: fmt::Debug + Send {
|
||||
}
|
||||
|
||||
/// Data in time-binned form.
|
||||
pub trait TimeBinned: Any + TypeName + TimeBinnable + Resettable + Collectable + erased_serde::Serialize {
|
||||
pub trait TimeBinned: Any + TypeName + TimeBinnable + Resettable + CollectableDyn + erased_serde::Serialize {
|
||||
fn clone_box_time_binned(&self) -> Box<dyn TimeBinned>;
|
||||
fn as_time_binnable_ref(&self) -> &dyn TimeBinnable;
|
||||
fn as_time_binnable_mut(&mut self) -> &mut dyn TimeBinnable;
|
||||
fn as_collectable_mut(&mut self) -> &mut dyn Collectable;
|
||||
fn as_collectable_mut(&mut self) -> &mut dyn CollectableDyn;
|
||||
fn edges_slice(&self) -> (&[u64], &[u64]);
|
||||
fn counts(&self) -> &[u64];
|
||||
fn mins(&self) -> Vec<f32>;
|
||||
@@ -230,7 +231,7 @@ pub trait TimeBinner: fmt::Debug + Send {
|
||||
/// Provides a time-binned representation of the implementing type.
|
||||
/// In contrast to `TimeBinnableType` this is meant for trait objects.
|
||||
pub trait TimeBinnable:
|
||||
fmt::Debug + WithLen + RangeOverlapInfo + Collectable + Any + AsAnyRef + AsAnyMut + Send
|
||||
fmt::Debug + WithLen + RangeOverlapInfo + CollectableDyn + Any + AsAnyRef + AsAnyMut + Send
|
||||
{
|
||||
// TODO implementors may fail if edges contain not at least 2 entries.
|
||||
fn time_binner_new(
|
||||
@@ -324,8 +325,8 @@ impl TypeName for Box<dyn TimeBinnable> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Collectable for Box<dyn TimeBinnable> {
|
||||
fn new_collector(&self) -> Box<dyn Collector> {
|
||||
impl CollectableDyn for Box<dyn TimeBinnable> {
|
||||
fn new_collector(&self) -> Box<dyn CollectorDyn> {
|
||||
self.as_ref().new_collector()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::collect_s::Collectable;
|
||||
use crate::collect_s::Collected;
|
||||
use crate::collect_s::CollectableDyn;
|
||||
use crate::collect_s::CollectedDyn;
|
||||
use crate::streamitem::RangeCompletableItem;
|
||||
use crate::streamitem::Sitemty;
|
||||
use crate::streamitem::StreamItem;
|
||||
@@ -22,7 +22,7 @@ pub trait TimeBinnableStreamTrait:
|
||||
}
|
||||
|
||||
pub trait CollectableStreamTrait:
|
||||
Stream<Item = Sitemty<Box<dyn Collectable>>> + WithTransformProperties + Send
|
||||
Stream<Item = Sitemty<Box<dyn CollectableDyn>>> + WithTransformProperties + Send
|
||||
{
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ impl TimeBinnableStreamTrait for TimeBinnableStreamBox {}
|
||||
pub struct CollectableStreamBox(pub Pin<Box<dyn CollectableStreamTrait>>);
|
||||
|
||||
impl Stream for CollectableStreamBox {
|
||||
type Item = Sitemty<Box<dyn Collectable>>;
|
||||
type Item = Sitemty<Box<dyn CollectableDyn>>;
|
||||
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
|
||||
self.0.poll_next_unpin(cx)
|
||||
@@ -182,7 +182,7 @@ impl<T> WithTransformProperties for stream::Empty<T> {
|
||||
impl<T> CollectableStreamTrait for stream::Empty<T>
|
||||
where
|
||||
T: Send,
|
||||
stream::Empty<T>: Stream<Item = Sitemty<Box<dyn Collectable>>>,
|
||||
stream::Empty<T>: Stream<Item = Sitemty<Box<dyn CollectableDyn>>>,
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user