rebuild
Source: crates/lvcs/src/runtime/replay.rs.
/// Why [`rebuild`] returned no actor.
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) enum RebuildError {
/// Entry `index` belongs to `actor`, not the actor being rebuilt.
Foreign {
/// Zero-based index of the entry.
index: u64,
/// The actor the entry belongs to.
actor: ActorId,
},
/// Entry `index` names `incarnation`, older than the `newest` one
/// before it.
OutOfOrder {
/// Zero-based index of the entry.
index: u64,
/// The incarnation the entry names.
incarnation: u64,
/// The newest incarnation an earlier entry named.
newest: u64,
},
/// Replay differed from the journal, so the rebuilt context can't be
/// trusted.
Diverged(Divergence),
}
/// Restart a router, mirror, or workspace machine from its own journal
/// entries (design §2 supervision, decision 56).
///
/// Feed `fresh`, a newly constructed machine, every entry for its
/// `(hooks.kind, key)` from all its earlier incarnations, in journal order,
/// and discard the outputs. Incarnations may skip numbers but never go back.
/// Spawn the result under the id `Incarnations::next` mints. Document
/// actors restart from their saves instead.
///
/// # Errors
///
/// [`RebuildError::Foreign`] when an entry belongs to another actor,
/// [`RebuildError::OutOfOrder`] when an entry's incarnation is older than an
/// earlier entry's, and [`RebuildError::Diverged`] when replay differs from
/// the journal.
pub(crate) fn rebuild<M, E, O, C, I>(
fresh: M,
hooks: &Hooks<M, O, C>,
key: &str,
entries: I,
) -> Result<M, RebuildError>
where
M: sml::Machine<E>,
C: PartialEq + Debug,
I: IntoIterator<Item = JournalEntry<E, C>>,