Move binned type, add tests
This commit is contained in:
@@ -7,27 +7,18 @@ use std::any::Any;
|
||||
use std::fmt;
|
||||
|
||||
pub trait Collector: fmt::Debug + Send {
|
||||
// TODO should require here Collectable?
|
||||
type Input;
|
||||
type Output: Collected;
|
||||
|
||||
fn len(&self) -> usize;
|
||||
|
||||
fn ingest(&mut self, item: &mut Self::Input);
|
||||
|
||||
fn ingest(&mut self, item: &mut dyn Collectable);
|
||||
fn set_range_complete(&mut self);
|
||||
|
||||
fn set_timed_out(&mut self);
|
||||
|
||||
fn result(&mut self) -> Result<Self::Output, Error>;
|
||||
fn result(&mut self) -> Result<Box<dyn Collected>, Error>;
|
||||
}
|
||||
|
||||
pub trait Collectable: fmt::Debug {
|
||||
type Collector: Collector<Input = Self>;
|
||||
|
||||
fn new_collector(&self) -> Self::Collector;
|
||||
pub trait Collectable: fmt::Debug + crate::AsAnyMut {
|
||||
fn new_collector(&self) -> Box<dyn Collector>;
|
||||
}
|
||||
|
||||
// TODO can this get removed?
|
||||
pub trait Collected: fmt::Debug + ToJsonResult + AsAnyRef + Send {}
|
||||
|
||||
erased_serde::serialize_trait_object!(Collected);
|
||||
@@ -53,6 +44,7 @@ impl Collected for Box<dyn Collected> {}
|
||||
#[derive(Debug)]
|
||||
pub struct CollectorDynDefault {}
|
||||
|
||||
// TODO remove?
|
||||
pub trait CollectorDyn: fmt::Debug + Send {
|
||||
fn len(&self) -> usize;
|
||||
|
||||
@@ -70,50 +62,15 @@ pub trait CollectableWithDefault {
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EventsCollector {
|
||||
coll: Box<dyn CollectorDyn>,
|
||||
}
|
||||
|
||||
impl EventsCollector {
|
||||
pub fn new(coll: Box<dyn CollectorDyn>) -> Self {
|
||||
Self { coll }
|
||||
}
|
||||
}
|
||||
|
||||
impl Collector for EventsCollector {
|
||||
type Input = Box<dyn Events>;
|
||||
|
||||
// TODO this Output trait does not differentiate between e.g. collected events, collected bins, different aggs, etc...
|
||||
type Output = Box<dyn Collected>;
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.coll.len()
|
||||
}
|
||||
|
||||
fn ingest(&mut self, item: &mut Self::Input) {
|
||||
self.coll.ingest(item.as_collectable_with_default_mut());
|
||||
}
|
||||
|
||||
fn set_range_complete(&mut self) {
|
||||
self.coll.set_range_complete()
|
||||
}
|
||||
|
||||
fn set_timed_out(&mut self) {
|
||||
self.coll.set_timed_out()
|
||||
}
|
||||
|
||||
fn result(&mut self) -> Result<Self::Output, Error> {
|
||||
self.coll.result()
|
||||
impl crate::AsAnyMut for Box<dyn Events> {
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Collectable for Box<dyn Events> {
|
||||
type Collector = EventsCollector;
|
||||
|
||||
fn new_collector(&self) -> Self::Collector {
|
||||
let coll = CollectableWithDefault::new_collector(self.as_ref());
|
||||
EventsCollector::new(coll)
|
||||
fn new_collector(&self) -> Box<dyn Collector> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,14 +78,11 @@ impl Collectable for Box<dyn Events> {
|
||||
pub struct TimeBinnedCollector {}
|
||||
|
||||
impl Collector for TimeBinnedCollector {
|
||||
type Input = Box<dyn crate::TimeBinned>;
|
||||
type Output = Box<dyn Collected>;
|
||||
|
||||
fn len(&self) -> usize {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn ingest(&mut self, _item: &mut Self::Input) {
|
||||
fn ingest(&mut self, _item: &mut dyn Collectable) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
@@ -140,15 +94,19 @@ impl Collector for TimeBinnedCollector {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn result(&mut self) -> Result<Self::Output, Error> {
|
||||
fn result(&mut self) -> Result<Box<dyn Collected>, Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::AsAnyMut for Box<dyn crate::TimeBinned> {
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Collectable for Box<dyn crate::TimeBinned> {
|
||||
type Collector = TimeBinnedCollector;
|
||||
|
||||
fn new_collector(&self) -> Self::Collector {
|
||||
todo!()
|
||||
fn new_collector(&self) -> Box<dyn Collector> {
|
||||
self.as_ref().new_collector()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ use serde::Serialize;
|
||||
use std::any::Any;
|
||||
use std::fmt;
|
||||
|
||||
// TODO rename to `Typed`
|
||||
pub trait CollectorType: Send + Unpin + WithLen {
|
||||
type Input: Collectable;
|
||||
type Output: Collected + ToJsonResult + Serialize;
|
||||
@@ -24,6 +25,7 @@ pub trait Collector: Send + Unpin + WithLen {
|
||||
fn result(&mut self) -> Result<Box<dyn ToJsonResult>, Error>;
|
||||
}
|
||||
|
||||
// TODO rename to `Typed`
|
||||
pub trait CollectableType {
|
||||
type Collector: CollectorType<Input = Self>;
|
||||
fn new_collector() -> Self::Collector;
|
||||
|
||||
@@ -61,14 +61,8 @@ pub trait AsAnyMut {
|
||||
fn as_any_mut(&mut self) -> &mut dyn Any;
|
||||
}
|
||||
|
||||
/*impl AsAnyRef for Box<dyn AsAnyRef> {
|
||||
fn as_any_ref(&self) -> &dyn Any {
|
||||
self.as_ref().as_any_ref()
|
||||
}
|
||||
}*/
|
||||
|
||||
/// Data in time-binned form.
|
||||
pub trait TimeBinned: Any + TimeBinnable {
|
||||
pub trait TimeBinned: Any + TimeBinnable + crate::collect_c::Collectable {
|
||||
fn as_time_binnable_dyn(&self) -> &dyn TimeBinnable;
|
||||
fn as_collectable_mut(&mut self) -> &mut dyn Collectable;
|
||||
fn edges_slice(&self) -> (&[u64], &[u64]);
|
||||
|
||||
Reference in New Issue
Block a user