Skip to content

Commit f9598e2

Browse files
committed
Add Debug impls for data crate
1 parent d19b9bd commit f9598e2

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
lines changed

crates/data/src/aggregation.rs

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//! Defines the `BarAggregator` trait and core aggregation types (tick, volume, value, time),
1919
//! along with the `BarBuilder` and `BarAggregatorCore` helpers for constructing bars.
2020
21-
use std::{any::Any, cell::RefCell, ops::Add, rc::Rc};
21+
use std::{any::Any, cell::RefCell, fmt::Debug, ops::Add, rc::Rc};
2222

2323
use chrono::TimeDelta;
2424
use nautilus_common::{
@@ -42,7 +42,7 @@ use nautilus_model::{
4242
/// Trait for aggregating incoming price and trade events into time-, tick-, volume-, or value-based bars.
4343
///
4444
/// Implementors receive updates and produce completed bars via handlers, with support for partial and batch updates.
45-
pub trait BarAggregator: Any {
45+
pub trait BarAggregator: Any + Debug {
4646
/// The [`BarType`] to be aggregated.
4747
fn bar_type(&self) -> BarType;
4848
/// If the aggregator is running and will receive data from the message bus.
@@ -102,6 +102,7 @@ impl dyn BarAggregator {
102102
}
103103

104104
/// Provides a generic bar builder for aggregation.
105+
#[derive(Debug)]
105106
pub struct BarBuilder {
106107
bar_type: BarType,
107108
price_precision: u8,
@@ -318,6 +319,18 @@ where
318319
batch_mode: bool,
319320
}
320321

322+
impl<H: FnMut(Bar)> Debug for BarAggregatorCore<H> {
323+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
324+
f.debug_struct(stringify!(BarAggregatorCore))
325+
.field("bar_type", &self.bar_type)
326+
.field("builder", &self.builder)
327+
.field("await_partial", &self.await_partial)
328+
.field("is_running", &self.is_running)
329+
.field("batch_mode", &self.batch_mode)
330+
.finish()
331+
}
332+
}
333+
321334
impl<H> BarAggregatorCore<H>
322335
where
323336
H: FnMut(Bar),
@@ -417,6 +430,15 @@ where
417430
cum_value: f64,
418431
}
419432

433+
impl<H: FnMut(Bar)> Debug for TickBarAggregator<H> {
434+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
435+
f.debug_struct("TickBarAggregator")
436+
.field("core", &self.core)
437+
.field("cum_value", &self.cum_value)
438+
.finish()
439+
}
440+
}
441+
420442
impl<H> TickBarAggregator<H>
421443
where
422444
H: FnMut(Bar),
@@ -535,6 +557,14 @@ where
535557
core: BarAggregatorCore<H>,
536558
}
537559

560+
impl<H: FnMut(Bar)> Debug for VolumeBarAggregator<H> {
561+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
562+
f.debug_struct("VolumeBarAggregator")
563+
.field("core", &self.core)
564+
.finish()
565+
}
566+
}
567+
538568
impl<H> VolumeBarAggregator<H>
539569
where
540570
H: FnMut(Bar),
@@ -669,6 +699,15 @@ where
669699
cum_value: f64,
670700
}
671701

702+
impl<H: FnMut(Bar)> Debug for ValueBarAggregator<H> {
703+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
704+
f.debug_struct("ValueBarAggregator")
705+
.field("core", &self.core)
706+
.field("cum_value", &self.cum_value)
707+
.finish()
708+
}
709+
}
710+
672711
impl<H> ValueBarAggregator<H>
673712
where
674713
H: FnMut(Bar),
@@ -826,7 +865,22 @@ where
826865
skip_first_non_full_bar: bool,
827866
}
828867

829-
#[derive(Clone)]
868+
impl<H: FnMut(Bar)> Debug for TimeBarAggregator<H> {
869+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
870+
f.debug_struct(stringify!(TimeBarAggregator))
871+
.field("core", &self.core)
872+
.field("build_with_no_updates", &self.build_with_no_updates)
873+
.field("timestamp_on_close", &self.timestamp_on_close)
874+
.field("is_left_open", &self.is_left_open)
875+
.field("timer_name", &self.timer_name)
876+
.field("interval_ns", &self.interval_ns)
877+
.field("composite_bar_build_delay", &self.composite_bar_build_delay)
878+
.field("skip_first_non_full_bar", &self.skip_first_non_full_bar)
879+
.finish()
880+
}
881+
}
882+
883+
#[derive(Clone, Debug)]
830884
pub struct NewBarCallback<H: FnMut(Bar)> {
831885
aggregator: Rc<RefCell<TimeBarAggregator<H>>>,
832886
}

crates/data/src/engine/book.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub struct BookSnapshotInfo {
4343
pub interval_ms: NonZeroUsize,
4444
}
4545

46+
#[derive(Debug)]
4647
pub struct BookUpdater {
4748
pub id: Ustr,
4849
pub instrument_id: InstrumentId,
@@ -88,6 +89,7 @@ impl MessageHandler for BookUpdater {
8889
}
8990
}
9091

92+
#[derive(Debug)]
9193
pub struct BookSnapshotter {
9294
pub id: Ustr,
9395
pub timer_name: Ustr,

crates/data/src/engine/handlers.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use ustr::Ustr;
2222
use crate::aggregation::BarAggregator;
2323

2424
// Quote ticks -> bar aggregator
25+
#[derive(Debug)]
2526
pub struct BarQuoteHandler {
2627
aggregator: Rc<RefCell<Box<dyn BarAggregator>>>,
2728
bar_type: BarType,
@@ -53,6 +54,7 @@ impl MessageHandler for BarQuoteHandler {
5354
}
5455

5556
// Trade ticks -> bar aggregator
57+
#[derive(Debug)]
5658
pub struct BarTradeHandler {
5759
aggregator: Rc<RefCell<Box<dyn BarAggregator>>>,
5860
bar_type: BarType,
@@ -84,6 +86,7 @@ impl MessageHandler for BarTradeHandler {
8486
}
8587

8688
// Composite bars -> bar aggregator
89+
#[derive(Debug)]
8790
pub struct BarBarHandler {
8891
aggregator: Rc<RefCell<Box<dyn BarAggregator>>>,
8992
bar_type: BarType,

crates/data/src/engine/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ use crate::{
9393
};
9494

9595
/// Provides a high-performance `DataEngine` for all environments.
96+
#[derive(Debug)]
9697
pub struct DataEngine {
9798
clock: Rc<RefCell<dyn Clock>>,
9899
cache: Rc<RefCell<Cache>>,

crates/data/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@
3131
#![warn(rustc::all)]
3232
#![deny(unsafe_code)]
3333
#![deny(nonstandard_style)]
34+
#![deny(missing_debug_implementations)]
3435
#![deny(rustdoc::broken_intra_doc_links)]
3536
#![deny(clippy::missing_errors_doc)]
3637
#![deny(clippy::missing_panics_doc)]
3738

38-
// Uncomment once we've added trivial debug impls everywhere
39-
// #![deny(missing_debug_implementations)]
40-
4139
pub mod aggregation;
4240
pub mod client;
4341
pub mod engine;

0 commit comments

Comments
 (0)