data_pipeline_rs/
node_visitor.rs1use std::fmt::Display;
2
3use crate::{node::Node, stats_producer::StatsProducer};
4
5pub trait NodeVisitor<T> {
6 fn visit(&mut self, node: &Node<T>);
7}
8
9#[derive(Default, Debug)]
10pub struct StatsNodeVisitor {
11 all_stats: serde_json::Value,
12}
13
14impl Display for StatsNodeVisitor {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 if f.alternate() {
17 write!(f, "{:#}", self.all_stats)
18 } else {
19 write!(f, "{}", self.all_stats)
20 }
21 }
22}
23
24impl<T> NodeVisitor<T> for StatsNodeVisitor {
25 fn visit(&mut self, node: &Node<T>) {
26 if let Some(stats) = node.get_stats() {
27 self.all_stats[node.name()] = stats;
28 }
29 }
30}