pub mod collect_c; pub mod collect_s; pub mod framable; pub mod isodate; pub mod scalar_ops; pub mod streamitem; pub mod subfr; pub mod bincode { pub use bincode::*; } use collect_c::CollectableWithDefault; use collect_s::Collectable; use collect_s::ToJsonResult; use netpod::NanoRange; use netpod::ScalarType; use netpod::Shape; use std::any::Any; use std::collections::VecDeque; use std::fmt; pub trait WithLen { fn len(&self) -> usize; } // TODO can probably be removed. pub trait TimeBins { fn ts_min(&self) -> Option; fn ts_max(&self) -> Option; fn ts_min_max(&self) -> Option<(u64, u64)>; } pub enum Fits { Empty, Lower, Greater, Inside, PartlyLower, PartlyGreater, PartlyLowerAndGreater, } pub trait RangeOverlapInfo { fn ends_before(&self, range: NanoRange) -> bool; fn ends_after(&self, range: NanoRange) -> bool; fn starts_after(&self, range: NanoRange) -> bool; } pub trait EmptyForScalarTypeShape { fn empty(scalar_type: ScalarType, shape: Shape) -> Self; } pub trait EmptyForShape { fn empty(shape: Shape) -> Self; } pub trait Empty { fn empty() -> Self; } pub trait Appendable: Empty + WithLen { fn push(&mut self, ts: u64, pulse: u64, value: STY); } pub trait TypeName { fn type_name(&self) -> String; } pub trait AppendEmptyBin { fn append_empty_bin(&mut self, ts1: u64, ts2: u64); } pub trait AsAnyRef { fn as_any_ref(&self) -> &dyn Any; } pub trait AsAnyMut { fn as_any_mut(&mut self) -> &mut dyn Any; } impl AsAnyRef for Box where T: AsAnyRef + ?Sized, { fn as_any_ref(&self) -> &dyn Any { self.as_ref().as_any_ref() } } impl AsAnyMut for Box where T: AsAnyMut + ?Sized, { fn as_any_mut(&mut self) -> &mut dyn Any { self.as_mut().as_any_mut() } } /// Data in time-binned form. pub trait TimeBinned: Any + TimeBinnable + crate::collect_c::Collectable + erased_serde::Serialize { fn as_time_binnable_dyn(&self) -> &dyn TimeBinnable; fn as_collectable_mut(&mut self) -> &mut dyn Collectable; fn edges_slice(&self) -> (&[u64], &[u64]); fn counts(&self) -> &[u64]; fn mins(&self) -> Vec; fn maxs(&self) -> Vec; fn avgs(&self) -> Vec; fn validate(&self) -> Result<(), String>; } pub trait TimeBinner: Send { fn ingest(&mut self, item: &dyn TimeBinnable); fn bins_ready_count(&self) -> usize; fn bins_ready(&mut self) -> Option>; /// If there is a bin in progress with non-zero count, push it to the result set. /// With push_empty == true, a bin in progress is pushed even if it contains no counts. fn push_in_progress(&mut self, push_empty: bool); /// Implies `Self::push_in_progress` but in addition, pushes a zero-count bin if the call /// to `push_in_progress` did not change the result count, as long as edges are left. /// The next call to `Self::bins_ready_count` must return one higher count than before. fn cycle(&mut self); fn set_range_complete(&mut self); fn empty(&self) -> Box; } // TODO remove the Any bound. Factor out into custom AsAny trait. /// 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 + Any + AsAnyRef + AsAnyMut + Send { // TODO implementors may fail if edges contain not at least 2 entries. fn time_binner_new(&self, edges: Vec, do_time_weight: bool) -> Box; // TODO just a helper for the empty result. fn to_box_to_json_result(&self) -> Box; } #[derive(Debug)] pub enum MergeError { NotCompatible, Full, } impl From for err::Error { fn from(e: MergeError) -> Self { format!("{e:?}").into() } } // TODO can I remove the Any bound? /// Container of some form of events, for use as trait object. pub trait Events: fmt::Debug + TypeName + Any + Collectable + CollectableWithDefault + TimeBinnable + WithLen + Send + erased_serde::Serialize + EventsNonObj { fn as_time_binnable(&self) -> &dyn TimeBinnable; fn verify(&self) -> bool; fn output_info(&self); fn as_collectable_mut(&mut self) -> &mut dyn Collectable; fn as_collectable_with_default_ref(&self) -> &dyn CollectableWithDefault; fn as_collectable_with_default_mut(&mut self) -> &mut dyn CollectableWithDefault; fn ts_min(&self) -> Option; fn ts_max(&self) -> Option; // TODO is this used? fn take_new_events_until_ts(&mut self, ts_end: u64) -> Box; fn new_empty(&self) -> Box; fn drain_into(&mut self, dst: &mut Box, range: (usize, usize)) -> Result<(), MergeError>; fn find_lowest_index_gt(&self, ts: u64) -> Option; fn find_lowest_index_ge(&self, ts: u64) -> Option; fn find_highest_index_lt(&self, ts: u64) -> Option; fn clone_dyn(&self) -> Box; fn partial_eq_dyn(&self, other: &dyn Events) -> bool; fn serde_id(&self) -> &'static str; fn nty_id(&self) -> u32; fn tss(&self) -> &VecDeque; fn pulses(&self) -> &VecDeque; } pub trait EventsNonObj { fn into_tss_pulses(self: Box) -> (VecDeque, VecDeque); } erased_serde::serialize_trait_object!(Events); impl PartialEq for Box { fn eq(&self, other: &Self) -> bool { Events::partial_eq_dyn(self.as_ref(), other.as_ref()) } } pub struct TransformProperties { pub needs_value: bool, } pub trait TransformStage { fn query_transform_properties(&self) -> TransformProperties; }