Skip to main content

vane_core/
flow_ctx.rs

1use tokio_util::sync::CancellationToken;
2
3use crate::flow_log::{FlowLogSink, FlowLogVerbosity, TrajectoryBuilder};
4
5pub struct FlowCtx<'a> {
6	pub span: &'a mut tracing::Span,
7	pub log: &'a mut dyn FlowLogSink,
8	pub cancel: &'a CancellationToken,
9	/// Verbosity selected when this connection was accepted. The listener
10	/// reads `engine::VerbosityState` once at `FlowCtx` construction;
11	/// in-flight connections retain the value they were built with.
12	pub verbosity: FlowLogVerbosity,
13	/// Walker-internal step accumulator. The executor pushes one entry
14	/// per node-visit and emits a single `FlowLogKind::Trajectory` event
15	/// from `finalize()` at terminate or error.
16	pub trajectory: TrajectoryBuilder,
17}
18
19#[cfg(test)]
20mod tests {
21	use parking_lot::Mutex;
22
23	use super::*;
24	use crate::conn_context::ConnId;
25	use crate::flow_log::FlowLogEvent;
26	use crate::ir::NodeId;
27
28	struct NullSink {
29		count: Mutex<u32>,
30	}
31
32	impl FlowLogSink for NullSink {
33		fn emit(&self, _event: FlowLogEvent) {
34			*self.count.lock() += 1;
35		}
36	}
37
38	// Compile-gate: a FlowCtx must be constructible from a concrete sink
39	// coerced to `&mut dyn FlowLogSink`, alongside a borrowed tracing::Span
40	// and CancellationToken, plus the verbosity / trajectory fields the
41	// walker reads. Field visibility regressions break this.
42	#[test]
43	fn flow_ctx_accepts_dyn_sink_and_borrowed_fields() {
44		let mut sink = NullSink { count: Mutex::new(0) };
45		let mut span = tracing::Span::none();
46		let cancel = CancellationToken::new();
47		let ctx = FlowCtx {
48			span: &mut span,
49			log: &mut sink as &mut dyn FlowLogSink,
50			cancel: &cancel,
51			verbosity: FlowLogVerbosity::Trajectory,
52			trajectory: TrajectoryBuilder::new(ConnId(0), NodeId::new(0), 0),
53		};
54		let _ = &ctx.span;
55		let _ = &ctx.log;
56		let _ = &ctx.cancel;
57		let _ = &ctx.verbosity;
58		let _ = &ctx.trajectory;
59	}
60}