Skip to main content

SimHook

Trait SimHook 

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

Source

fn create(next_id: &mut dyn FnMut() -> usize) -> Self

Creates every handle in this value, allocating fresh IDs via next_id.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<H: SimHook> SimHook for Option<H>

Source§

fn create(next_id: &mut dyn FnMut() -> usize) -> Self

Implementors§

Source§

impl<T, B: Boundedness> SimHook for OrderingHook<T, B>

Source§

impl<T, O: Ordering, R: Retries> SimHook for BatchHook<T, O, R>

Source§

impl<T> SimHook for SnapshotHook<T>