diff --git a/src/collect_s.rs b/src/collect_s.rs index 72bc643..7502e48 100644 --- a/src/collect_s.rs +++ b/src/collect_s.rs @@ -1,14 +1,12 @@ use crate::apitypes::ToUserFacingApiType; use crate::container::ByteEstimate; -use crate::timebin::BinningggContainerBinsDyn; +use crate::log::*; use crate::AsAnyMut; use crate::AsAnyRef; -use crate::Events; use crate::TypeName; use crate::WithLen; use daqbuf_err as err; use err::Error; -use netpod::log::*; use std::any; use std::any::Any; use std::fmt; @@ -123,36 +121,6 @@ pub trait CollectableDyn: fmt::Debug + WithLen + AsAnyRef + AsAnyMut + Send + Ty fn new_collector(&self) -> Box; } -impl TypeName for Box { - fn type_name(&self) -> String { - self.as_ref().type_name() - } -} - -impl WithLen for Box { - fn len(&self) -> usize { - WithLen::len(self.as_ref()) - } -} - -impl CollectableDyn for Box { - fn new_collector(&self) -> Box { - self.as_ref().new_collector() - } -} - -impl TypeName for Box { - fn type_name(&self) -> String { - self.as_ref().type_name() - } -} - -impl CollectableDyn for Box { - fn new_collector(&self) -> Box { - self.as_ref().new_collector() - } -} - impl CollectableDyn for T where T: CollectableType + 'static, diff --git a/src/container.rs b/src/container.rs index 20bc4c6..480af42 100644 --- a/src/container.rs +++ b/src/container.rs @@ -1,20 +1,3 @@ -use crate::Events; - pub trait ByteEstimate { fn byte_estimate(&self) -> u64; } - -impl ByteEstimate for Box { - fn byte_estimate(&self) -> u64 { - self.as_ref().byte_estimate() - } -} - -impl ByteEstimate for Box -where - T: ByteEstimate, -{ - fn byte_estimate(&self) -> u64 { - self.as_ref().byte_estimate() - } -} diff --git a/src/events.rs b/src/events.rs index 01a11ff..0f72b1d 100644 --- a/src/events.rs +++ b/src/events.rs @@ -1,13 +1,7 @@ pub use futures_util; -use crate::collect_s::CollectableDyn; -use crate::container::ByteEstimate; -use crate::timebin::BinningggContainerEventsDyn; -use daqbuf_err as err; use netpod::TsNano; use std::any::Any; -use std::collections::VecDeque; -use std::fmt; pub trait WithLen { fn len(&self) -> usize; @@ -48,20 +42,6 @@ pub trait TypeName { fn type_name(&self) -> String; } -pub trait AppendEmptyBin { - fn append_empty_bin(&mut self, ts1: u64, ts2: u64); -} - -// TODO rename to make it clear that this moves. Better use drain-into or something similar. -pub trait AppendAllFrom { - fn append_all_from(&mut self, src: &mut Self); -} - -// TODO check usage, probably only for legacy -pub trait HasNonemptyFirstBin { - fn has_nonempty_first_bin(&self) -> bool; -} - pub trait AsAnyRef { fn as_any_ref(&self) -> &dyn Any; } @@ -87,190 +67,3 @@ where self.as_mut().as_any_mut() } } - -// 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 - + CollectableDyn - + WithLen - + ByteEstimate - + Send - + erased_serde::Serialize - + EventsNonObj -{ - fn verify(&self) -> bool; - fn output_info(&self) -> String; - 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; - 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 dyn Events, - range: (usize, usize), - ) -> Result<(), err::Error>; - 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; - fn to_json_string(&self) -> String; - fn to_json_vec_u8(&self) -> Vec; - fn to_cbor_vec_u8(&self) -> Vec; - fn clear(&mut self); - // TODO: can not name EventsDim0 from here, so use trait object for now. Anyway is a workaround. - fn to_dim0_f32_for_binning(&self) -> Box; - fn to_container_events(&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 verify(&self) -> bool { - Events::verify(self.as_ref()) - } - - fn output_info(&self) -> String { - Events::output_info(self.as_ref()) - } - - fn as_collectable_mut(&mut self) -> &mut dyn CollectableDyn { - Events::as_collectable_mut(self.as_mut()) - } - - 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 CollectableDyn { - 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 dyn Events, - range: (usize, usize), - ) -> Result<(), err::Error> { - 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()) - } - - fn to_json_string(&self) -> String { - Events::to_json_string(self.as_ref()) - } - - fn to_json_vec_u8(&self) -> Vec { - Events::to_json_vec_u8(self.as_ref()) - } - - fn to_cbor_vec_u8(&self) -> Vec { - Events::to_cbor_vec_u8(self.as_ref()) - } - - fn clear(&mut self) { - Events::clear(self.as_mut()) - } - - fn to_dim0_f32_for_binning(&self) -> Box { - Events::to_dim0_f32_for_binning(self.as_ref()) - } - - fn to_container_events(&self) -> Box { - Events::to_container_events(self.as_ref()) - } -} diff --git a/src/lib.rs b/src/lib.rs index 01a75f8..6162b9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,9 +11,15 @@ pub mod streamitem; pub mod subfr; pub mod test; pub mod timebin; -pub mod transform; pub mod vecpreview; +mod log { + #[cfg(not(test))] + pub use netpod::log::*; + #[cfg(test)] + pub use netpod::log_direct::*; +} + pub mod bincode { pub use bincode::*; } diff --git a/src/timebin.rs b/src/timebin.rs index 1b95336..9fa3b86 100644 --- a/src/timebin.rs +++ b/src/timebin.rs @@ -1,8 +1,6 @@ use crate::apitypes::ToUserFacingApiType; use crate::collect_s::CollectableDyn; use crate::container::ByteEstimate; -use crate::merge::DrainIntoDstResult; -use crate::merge::DrainIntoNewDynResult; use crate::merge::MergeableDyn; use crate::AsAnyMut; use crate::AsAnyRef; @@ -11,7 +9,6 @@ use crate::WithLen; use netpod::BinnedRange; use netpod::BinnedRangeEnum; use netpod::TsNano; -use std::collections::VecDeque; use std::fmt; use std::ops::Range; @@ -111,51 +108,6 @@ pub trait BinningggContainerEventsDyn: fn as_collectable_dyn_mut(&mut self) -> &mut dyn CollectableDyn; } -impl MergeableDyn for Box -where - T: MergeableDyn, -{ - fn ts_min(&self) -> Option { - self.as_ref().ts_min() - } - - fn ts_max(&self) -> Option { - self.as_ref().ts_max() - } - - fn find_lowest_index_gt(&self, ts: TsNano) -> Option { - self.as_ref().find_lowest_index_gt(ts) - } - - fn find_lowest_index_ge(&self, ts: TsNano) -> Option { - self.as_ref().find_lowest_index_ge(ts) - } - - fn find_highest_index_lt(&self, ts: TsNano) -> Option { - self.as_ref().find_highest_index_lt(ts) - } - - fn tss_for_testing(&self) -> VecDeque { - self.as_ref().tss_for_testing() - } - - fn drain_into( - &mut self, - dst: &mut dyn MergeableDyn, - range: Range, - ) -> DrainIntoDstResult { - self.as_mut().drain_into(dst, range) - } - - fn drain_into_new(&mut self, range: Range) -> DrainIntoNewDynResult { - self.as_mut().drain_into_new(range) - } - - fn is_consistent(&self) -> bool { - self.as_ref().is_consistent() - } -} - pub trait BinningggContainerBinsDyn: fmt::Debug + Send + fmt::Display + TypeName + WithLen + AsAnyMut + CollectableDyn { diff --git a/src/transform.rs b/src/transform.rs deleted file mode 100644 index eeb91bb..0000000 --- a/src/transform.rs +++ /dev/null @@ -1,125 +0,0 @@ -use crate::collect_s::CollectableDyn; -use crate::streamitem::RangeCompletableItem; -use crate::streamitem::Sitemty; -use crate::streamitem::StreamItem; -use crate::Events; -use futures_util::stream; -use futures_util::Stream; -use futures_util::StreamExt; -use std::pin::Pin; -use std::task::Context; -use std::task::Poll; - -pub trait EventStreamTrait: - Stream>> + WithTransformProperties + Send -{ -} - -pub trait CollectableStreamTrait: - Stream>> + WithTransformProperties + Send -{ -} - -pub struct EventTransformProperties { - pub needs_value: bool, -} - -pub struct TransformProperties { - pub needs_one_before_range: bool, - pub needs_value: bool, -} - -pub trait WithTransformProperties { - fn query_transform_properties(&self) -> TransformProperties; -} - -impl WithTransformProperties for Box -where - T: WithTransformProperties, -{ - fn query_transform_properties(&self) -> TransformProperties { - self.as_ref().query_transform_properties() - } -} - -impl WithTransformProperties for Pin> -where - T: WithTransformProperties, -{ - fn query_transform_properties(&self) -> TransformProperties { - self.as_ref().query_transform_properties() - } -} - -pub struct IdentityTransform {} - -impl IdentityTransform { - pub fn default() -> Self { - Self {} - } -} - -impl WithTransformProperties for IdentityTransform { - fn query_transform_properties(&self) -> TransformProperties { - todo!() - } -} - -impl WithTransformProperties for stream::Iter { - fn query_transform_properties(&self) -> TransformProperties { - todo!() - } -} - -impl EventStreamTrait for stream::Iter where - T: core::iter::Iterator>> + Send -{ -} - -pub struct EventStreamBox(pub Pin>); - -impl From for EventStreamBox -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]); - Self(Box::pin(x)) - } -} - -pub struct CollectableStreamBox(pub Pin>); - -impl Stream for CollectableStreamBox { - type Item = Sitemty>; - - fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { - self.0.poll_next_unpin(cx) - } -} - -impl WithTransformProperties for CollectableStreamBox { - fn query_transform_properties(&self) -> TransformProperties { - todo!() - } -} - -impl CollectableStreamTrait for CollectableStreamBox {} - -impl WithTransformProperties for stream::Empty { - fn query_transform_properties(&self) -> TransformProperties { - todo!() - } -} - -impl CollectableStreamTrait for stream::Empty -where - T: Send, - stream::Empty: Stream>>, -{ -} - -impl CollectableStreamTrait for Pin> where T: CollectableStreamTrait {}