pub mod collect_s; pub mod container; pub mod framable; pub mod isodate; pub mod overlap; pub mod scalar_ops; pub mod streamitem; pub mod subfr; pub mod test; pub mod timebin; pub mod transform; pub mod bincode { pub use bincode::*; } pub use futures_util; use collect_s::Collectable; use container::ByteEstimate; use netpod::range::evrange::SeriesRange; use std::any::Any; use std::collections::VecDeque; use std::fmt; use timebin::TimeBinnable; pub trait WithLen { fn len(&self) -> usize; } 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() } } #[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 + TimeBinnable + WithLen + ByteEstimate + Send + erased_serde::Serialize + EventsNonObj { fn as_time_binnable_mut(&mut self) -> &mut 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 Collectable; fn as_collectable_with_default_mut(&mut self) -> &mut dyn Collectable; 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_evs(&self) -> Box; fn drain_into_evs(&mut self, dst: &mut Box, range: (usize, usize)) -> Result<(), MergeError>; fn find_lowest_index_gt_evs(&self, ts: u64) -> Option; fn find_lowest_index_ge_evs(&self, ts: u64) -> Option; fn find_highest_index_lt_evs(&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; fn frame_type_id(&self) -> u32; fn to_min_max_avg(&mut self) -> Box; } impl WithLen for Box { fn len(&self) -> usize { self.as_ref().len() } } 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()) } } impl EventsNonObj for Box { fn into_tss_pulses(self: Box) -> (VecDeque, VecDeque) { todo!() } } impl Events for Box { fn as_time_binnable_mut(&mut self) -> &mut dyn TimeBinnable { Events::as_time_binnable_mut(self.as_mut()) } fn verify(&self) -> bool { Events::verify(self.as_ref()) } fn output_info(&self) { Events::output_info(self.as_ref()) } fn as_collectable_mut(&mut self) -> &mut dyn Collectable { Events::as_collectable_mut(self.as_mut()) } fn as_collectable_with_default_ref(&self) -> &dyn Collectable { Events::as_collectable_with_default_ref(self.as_ref()) } fn as_collectable_with_default_mut(&mut self) -> &mut dyn Collectable { Events::as_collectable_with_default_mut(self.as_mut()) } fn ts_min(&self) -> Option { Events::ts_min(self.as_ref()) } fn ts_max(&self) -> Option { Events::ts_max(self.as_ref()) } fn take_new_events_until_ts(&mut self, ts_end: u64) -> Box { Events::take_new_events_until_ts(self.as_mut(), ts_end) } fn new_empty_evs(&self) -> Box { Events::new_empty_evs(self.as_ref()) } fn drain_into_evs(&mut self, dst: &mut Box, range: (usize, usize)) -> Result<(), MergeError> { Events::drain_into_evs(self.as_mut(), dst, range) } fn find_lowest_index_gt_evs(&self, ts: u64) -> Option { Events::find_lowest_index_gt_evs(self.as_ref(), ts) } fn find_lowest_index_ge_evs(&self, ts: u64) -> Option { Events::find_lowest_index_ge_evs(self.as_ref(), ts) } fn find_highest_index_lt_evs(&self, ts: u64) -> Option { Events::find_highest_index_lt_evs(self.as_ref(), ts) } fn clone_dyn(&self) -> Box { Events::clone_dyn(self.as_ref()) } fn partial_eq_dyn(&self, other: &dyn Events) -> bool { Events::partial_eq_dyn(self.as_ref(), other) } fn serde_id(&self) -> &'static str { Events::serde_id(self.as_ref()) } fn nty_id(&self) -> u32 { Events::nty_id(self.as_ref()) } fn tss(&self) -> &VecDeque { Events::tss(self.as_ref()) } fn pulses(&self) -> &VecDeque { Events::pulses(self.as_ref()) } fn frame_type_id(&self) -> u32 { Events::frame_type_id(self.as_ref()) } fn to_min_max_avg(&mut self) -> Box { Events::to_min_max_avg(self.as_mut()) } }