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.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".