pub struct Dfir<Tick> { /* private fields */ }Expand description
An executable DFIR dataflow, as created by
dfir_syntax!. Provides the Self::run,
Self::run_available, and Self::run_tick family of methods to
execute the dataflow.
§Design
The inline codegen generates an async move |df: &mut Context| closure that captures
dataflow-specific state (handoff buffers, source iterators) and receives the Context
(tick counter, metrics) by reference each tick. Dfir owns both the
closure and the context, and coordinates tick lifecycle and idle/wake behavior.
We use a single opaque closure rather than generating a bespoke struct per dataflow because:
- The closure naturally captures exactly the state it needs with correct lifetimes
- No codegen needed for struct definitions, field accessors, or initialization
- Rust’s async closure machinery handles the complex state machine (suspend/resume across
.awaitpoints) that would be very difficult to replicate in a generated struct
The Tick type parameter is bounded by [TickClosure] (not AsyncFnMut directly) to
support type erasure via [TickClosureErased] / DfirErased for heterogeneous
collections (e.g., the sim runtime storing multiple locations in a Vec). The concrete
(non-erased) path used by trybuild and embedded has zero overhead.
Implementations§
Source§impl<Tick: TickClosure> Dfir<Tick>
impl<Tick: TickClosure> Dfir<Tick>
Sourcepub fn meta_graph(&self) -> Option<&DfirGraph>
Available on crate feature meta only.
pub fn meta_graph(&self) -> Option<&DfirGraph>
meta only.Return a handle to the meta graph, if set.
Sourcepub fn diagnostics(&self) -> Option<&[Diagnostic<SerdeSpan>]>
Available on crate feature meta only.
pub fn diagnostics(&self) -> Option<&[Diagnostic<SerdeSpan>]>
meta only.Returns any diagnostics generated by the surface syntax macro.
Sourcepub fn metrics(&self) -> Rc<DfirMetrics>
pub fn metrics(&self) -> Rc<DfirMetrics>
Returns a reference-counted handle to the continually-updated runtime metrics for this DFIR instance.
Sourcepub fn current_tick(&self) -> TickInstant
pub fn current_tick(&self) -> TickInstant
Gets the current tick (local time) count.
Sourcepub fn metrics_intervals(&self) -> DfirMetricsIntervals
pub fn metrics_intervals(&self) -> DfirMetricsIntervals
Returns a DfirMetricsIntervals handle where each call to
DfirMetricsIntervals::take_interval ends the current interval and returns its metrics.
The first call to take_interval returns metrics since this DFIR instance was created. Each subsequent call to
take_interval returns metrics since the previous call.
Cloning the handle “forks” it from the original, as afterwards each interval may return different metrics
depending on when exactly take_interval is called.
Source§impl<Tick: TickClosure> Dfir<Tick>
impl<Tick: TickClosure> Dfir<Tick>
Sourcepub async fn run_tick(&mut self) -> bool
pub async fn run_tick(&mut self) -> bool
Run a single tick. Returns true if any subgraph received input data.
Checks both handoff buffers (via work_done flag set in generated recv port code)
and external events (via can_start_tick set by wakers/schedule_subgraph).
Sourcepub fn run_tick_sync(&mut self) -> bool
pub fn run_tick_sync(&mut self) -> bool
Run a single tick synchronously. Panics if the tick yields (async suspension).
Returns true if work was done (see Self::run_tick).
Sourcepub async fn run_available(&mut self)
Available on crate feature tokio only.
pub async fn run_available(&mut self)
tokio only.Run ticks as long as work is available, then return.
Sourcepub fn run_available_sync(&mut self)
pub fn run_available_sync(&mut self)
Self::run_available but panics if any tick yields asynchronously.
Source§impl<Tick: 'static + for<'a> AsyncFnMut(&'a mut Context) -> bool> Dfir<Tick>
impl<Tick: 'static + for<'a> AsyncFnMut(&'a mut Context) -> bool> Dfir<Tick>
Sourcepub fn into_erased(self) -> DfirErased
pub fn into_erased(self) -> DfirErased
Type-erase the tick closure for use in heterogeneous collections.
Wraps the concrete async closure in [TickClosureErased], which boxes the future
returned by each tick call. This adds one heap allocation per tick, but enables
storing multiple Dfirs with different closure types in a single Vec.
Only needed for the sim runtime path. The trybuild and embedded paths keep the concrete type and pay no erasure cost.
Auto Trait Implementations§
impl<Tick> !RefUnwindSafe for Dfir<Tick>
impl<Tick> !Send for Dfir<Tick>
impl<Tick> !Sync for Dfir<Tick>
impl<Tick> !UnwindSafe for Dfir<Tick>
impl<Tick> Freeze for Dfir<Tick>where
Tick: Freeze,
impl<Tick> Unpin for Dfir<Tick>where
Tick: Unpin,
impl<Tick> UnsafeUnpin for Dfir<Tick>where
Tick: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> ToSinkBuild for T
impl<T> ToSinkBuild for T
§fn iter_to_sink_build(self) -> SendIterBuild<Self>
fn iter_to_sink_build(self) -> SendIterBuild<Self>
§fn stream_to_sink_build(self) -> SendStreamBuild<Self>where
Self: Sized + Stream,
fn stream_to_sink_build(self) -> SendStreamBuild<Self>where
Self: Sized + Stream,
SinkBuild] adaptor chain to send all items from self as a [Stream].