pub struct Dfir<Tick: TickClosure> { /* 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<M>| 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) so
that the runners can be split by what the closure supports (TickClosureSync /
TickClosureAsync) and to support type erasure ([TickClosureErasedSync],
[TickClosureErasedAsync], [TickClosureErased]) for storing graphs of different concrete
types in one place (a struct field, or the sim runtime’s Vec of locations). The concrete
(non-erased) path used by trybuild and embedded has zero overhead.
§Metrics
Whether this Dfir tracks runtime metrics is determined statically by
TickClosure::Metrics (see MetricsState). The Self::metrics and
Self::metrics_intervals accessors only exist when Tick::Metrics = DfirMetrics. When
returning a Dfir from a function via impl TickClosureBoth, use
Dfir<impl TickClosureBoth<Metrics = DfirMetrics>> if callers need to access the metrics.
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.Returns the meta graph, if set.
The graph is deserialized from its JSON representation on each call, so callers which need it multiple times should store the result.
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 current_tick(&self) -> TickInstant
pub fn current_tick(&self) -> TickInstant
Gets the current tick (local time) count.
Source§impl<Tick: TickClosure<Metrics = DfirMetrics>> Dfir<Tick>
Metrics accessors, only available when metrics tracking is enabled (Tick::Metrics = DfirMetrics).
impl<Tick: TickClosure<Metrics = DfirMetrics>> Dfir<Tick>
Metrics accessors, only available when metrics tracking is enabled (Tick::Metrics = DfirMetrics).
Sourcepub fn metrics(&self) -> Arc<DfirMetrics> ⓘ
pub fn metrics(&self) -> Arc<DfirMetrics> ⓘ
Returns a reference-counted handle to the continually-updated runtime metrics for this DFIR instance.
Only available when metrics tracking is enabled, see MetricsState.
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.
Only available when metrics tracking is enabled, see MetricsState.
Source§impl<Tick: TickClosureAsync> Dfir<Tick>
The async runners. Available when the tick closure is TickClosureAsync.
impl<Tick: TickClosureAsync> Dfir<Tick>
The async runners. Available when the tick closure is TickClosureAsync.
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 waker/schedule_subgraph).
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.
Source§impl<Tick: TickClosureSync> Dfir<Tick>
The sync runners. Available when the tick closure is TickClosureSync.
impl<Tick: TickClosureSync> Dfir<Tick>
The sync runners. Available when the tick closure is TickClosureSync.
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).
Goes through TickClosureSync::call_tick_sync, which stays allocation-free even for the
type-erased DfirErasedSync / DfirErased.
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: TickClosure + 'static> Dfir<Tick>
Type erasure. Each option keeps the MetricsState typestate and gives the graph a nameable
type, so it can be stored in a struct field or a heterogeneous collection. They differ in which
runners the result supports and, accordingly, in what its vtable carries; see
TickClosure.
impl<Tick: TickClosure + 'static> Dfir<Tick>
Type erasure. Each option keeps the MetricsState typestate and gives the graph a nameable
type, so it can be stored in a struct field or a heterogeneous collection. They differ in which
runners the result supports and, accordingly, in what its vtable carries; see
TickClosure.
Sourcepub fn into_erased_sync(self) -> DfirErasedSync<Tick::Metrics>where
Tick: TickClosureSync,
pub fn into_erased_sync(self) -> DfirErasedSync<Tick::Metrics>where
Tick: TickClosureSync,
Type-erase for the sync runners only: the result is DfirErasedSync.
Allocation-free per tick. Use this to store a graph that is driven synchronously, e.g. from an embedding application’s own event loop.
Sourcepub fn into_erased_async(self) -> DfirErasedAsync<Tick::Metrics>where
Tick: TickClosureAsync,
pub fn into_erased_async(self) -> DfirErasedAsync<Tick::Metrics>where
Tick: TickClosureAsync,
Type-erase for the async runners only: the result is DfirErasedAsync.
Boxes the tick’s future, one allocation per tick. Use this for graphs driven by
Dfir::run_tick / Dfir::run_available / Dfir::run, e.g. the sim runtime.
Sourcepub fn into_erased(self) -> DfirErased<Tick::Metrics>where
Tick: TickClosureBoth,
pub fn into_erased(self) -> DfirErased<Tick::Metrics>where
Tick: TickClosureBoth,
Type-erase keeping both the sync and the async runners: the result is DfirErased.
Prefer Self::into_erased_sync or Self::into_erased_async when only one kind of
runner is used, so the other path is not instantiated.
Auto Trait Implementations§
impl<Tick> !RefUnwindSafe for Dfir<Tick>
impl<Tick> !Sync for Dfir<Tick>
impl<Tick> !UnwindSafe for Dfir<Tick>
impl<Tick> Forget for Dfir<Tick>
impl<Tick> Freeze for Dfir<Tick>where
Tick: Freeze,
*const ArcInner<WakeState> is !null: Freeze,
PhantomData<ArcInner<WakeState>>: Freeze,
<<Tick as TickClosure>::Metrics as MetricsState>::Handle: Freeze,
*const u8 is !null: Freeze,
PhantomData<Pin<Box<dyn Future<Output = ()> + Send>>>: Freeze,
PhantomData<u8>: Freeze,
PhantomData<Diagnostic<SerdeSpan>>: Freeze,
impl<Tick> Move for Dfir<Tick>
impl<Tick> Send for Dfir<Tick>
impl<Tick> Unpin for Dfir<Tick>
impl<Tick> UnsafeUnpin for Dfir<Tick>where
Tick: UnsafeUnpin,
*const ArcInner<WakeState> is !null: UnsafeUnpin,
PhantomData<ArcInner<WakeState>>: UnsafeUnpin,
<<Tick as TickClosure>::Metrics as MetricsState>::Handle: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<Pin<Box<dyn Future<Output = ()> + Send>>>: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<Diagnostic<SerdeSpan>>: 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].