Skip to main content

Dfir

Struct Dfir 

Source
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 .await points) 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>

Source

pub fn meta_graph(&self) -> Option<&DfirGraph>

Available on crate feature meta only.

Return a handle to the meta graph, if set.

Source

pub fn diagnostics(&self) -> Option<&[Diagnostic<SerdeSpan>]>

Available on crate feature meta only.

Returns any diagnostics generated by the surface syntax macro.

Source

pub fn metrics(&self) -> Rc<DfirMetrics>

Returns a reference-counted handle to the continually-updated runtime metrics for this DFIR instance.

Source

pub fn current_tick(&self) -> TickInstant

Gets the current tick (local time) count.

Source

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>

Source

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).

Source

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).

Source

pub async fn run_available(&mut self)

Available on crate feature tokio only.

Run ticks as long as work is available, then return.

Source

pub fn run_available_sync(&mut self)

Self::run_available but panics if any tick yields asynchronously.

Source

pub async fn run(&mut self) -> Never

Available on crate feature tokio only.

Run forever, processing ticks when work is available and yielding when idle.

Source§

impl<Tick: 'static + for<'a> AsyncFnMut(&'a mut Context) -> bool> Dfir<Tick>

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn iter_to_sink_build(self) -> SendIterBuild<Self>
where Self: Sized + Iterator,

Starts a [SinkBuild] adaptor chain to send all items from self as an Iterator.
§

fn stream_to_sink_build(self) -> SendStreamBuild<Self>
where Self: Sized + Stream,

Starts a [SinkBuild] adaptor chain to send all items from self as a [Stream].
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more