docs/generated/contracts.mdgenerated from code

Reference · 2 min read

replay

Contracts: replay.

Source: crates/lvcs-runtime/src/replay.rs.

ruston main
1/// Where a replayed entry first differed from the journal.2#[derive(Debug, Clone, PartialEq, Eq)]3pub struct Divergence {4    /// Zero-based index of the entry among those replayed.5    pub index: u64,6    /// What differed: `trace`, `state_before`, `state_after`, or `stopped`7    /// (the machine had reached `X` and took no step).8    pub what: &'static str,9    /// What the journal recorded.10    pub expected: String,11    /// What the replayed machine did.12    pub actual: String,13}1415/// The other end of a capturing close: the step the machine last ran.16pub struct Capture<E, O, C = ()> {17    /// The captured step.18    inner: Arc<Mutex<Captured<E, O, C>>>,19}2021/// A close that captures each step for replay, and its [`Capture`].22pub fn capture<E, O, C>() -> (Close<E, O, C>, Capture<E, O, C>)23where24    E: Send + 'static,25    O: Send + 'static,26    C: Send + 'static,27{28    let inner = Arc::new(Mutex::new(Captured { last: None }));29    let sink = Arc::clone(&inner);30    let close: Close<E, O, C> = Arc::new(move |stepped| {31        lock(&sink).last = Some(stepped);32        super::closed()33    });34    (close, Capture { inner })35}3637/// Replay `entries` through `submit`, which steps the machine built with38/// `capture`'s close (`|ev| now(machine.process_event_async(ev))`), and39/// return the outputs it produced (recorded, never executed) and the first40/// divergence, at which it stops.41pub fn replay<E, O, C, I>(42    mut submit: impl FnMut(E) -> bool,43    capture: &Capture<E, O, C>,44    entries: I,45) -> (Vec<O>, Option<Divergence>)46where47    C: PartialEq + Debug,48    I: IntoIterator<Item = JournalEntry<E, C>>,