pub trait SimHook {
// Required method
fn create(next_id: &mut dyn FnMut() -> usize) -> Self;
}Expand description
A simulator hook handle (or a set of them) that can be created in one call to
FlowBuilder::sim_hook.
Individual handle types implement this trait, and a struct of handles (a component’s
“testing interface”) can implement it by creating every field. Fields are typed
Option<...> so the struct doubles as a composite hook payload: its Default
(“no hooks”) is what a plain nondet!(...) guard carries, while flow.sim_hook()
fills in every handle:
#[derive(Clone, Copy, Default)]
pub struct CounterHooks {
pub batch: Option<BatchHook<u32>>,
pub snapshot: Option<SnapshotHook<u64>>,
}
impl SimHook for CounterHooks {
fn create(next_id: &mut dyn FnMut() -> usize) -> Self {
CounterHooks {
batch: SimHook::create(next_id),
snapshot: SimHook::create(next_id),
}
}
}Such structs nest (a field can itself be a struct of handles), and since handles are
Copy a test can pass the struct around or destructure it freely.
Each handle’s SimHook impl carries the trait bounds that the scripted simulation
codegen for its operator kind requires (serde round-tripping for decisions, equality
for value-naming decisions, Hash + Eq + Clone keys for keyed buffers). Since handles
can only be created through this trait, binding a hook to an operator over unsupported
types fails at the flow.sim_hook() call — an ordinary compile error in the test crate
— instead of surfacing as a rustc failure inside the generated simulation dylib.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".