pub struct RunnerSnapshot {
pub current_node: Option<String>,
pub visits: HashMap<String, u32>,
pub once_seen: HashSet<String>,
}Expand description
A point-in-time snapshot of the dialogue session’s mutable state.
Use Runner::snapshot to capture and
Runner::restore to apply.
The snapshot records:
- which node was active (
current_node), - how many times each node has been visited (
visits), - which
<<once>>blocks have already fired (once_seen).
Variable storage is not included - it is the host’s responsibility to
persist HashMapStorage (or their own
VariableStorage impl) alongside the snapshot when
building a full save file.
With the serde feature, this type also derives Serialize / Deserialize
so you can write it to disk as JSON or another format.
§Save / load example
Both the snapshot and variable storage must be serialised together when you persist to disk. Neither is complete without the other.
use bubbles::{HashMapStorage, Runner, Value, VariableStorage, compile};
let src = "title: A\n---\n<<set $gold = 10>>\nHello!\n===\n";
let prog = compile(src).unwrap();
// First session
let mut runner = Runner::new(prog.clone(), HashMapStorage::new());
runner.start("A").unwrap();
let _ = runner.next_event(); // NodeStarted
let _ = runner.next_event(); // (set $gold side-effect, then Line)
let snap = runner.snapshot();
let snap_json = serde_json::to_string(&snap).unwrap();
let vars_json = serde_json::to_string(runner.storage()).unwrap();
let saved_vars: HashMapStorage = serde_json::from_str(&vars_json).unwrap();
let saved_snap: bubbles::RunnerSnapshot = serde_json::from_str(&snap_json).unwrap();
let mut runner2 = Runner::new(prog, saved_vars);
runner2.restore(saved_snap).unwrap();
// runner2 is back at the beginning of node "A" with $gold already set.Fields§
§current_node: Option<String>The node that was executing when the snapshot was taken.
When restoring, Runner::restore will
restart execution from the beginning of this node. This is intentional:
the in-progress statement list is not serialised because it would
require the full AST to be round-tripped.
visits: HashMap<String, u32>How many times each node has been visited.
once_seen: HashSet<String>IDs of <<once>> blocks (and once-line-variants) that have already
fired and must not fire again.
Trait Implementations§
Source§impl Clone for RunnerSnapshot
impl Clone for RunnerSnapshot
Source§fn clone(&self) -> RunnerSnapshot
fn clone(&self) -> RunnerSnapshot
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RunnerSnapshot
impl Debug for RunnerSnapshot
Source§impl PartialEq for RunnerSnapshot
impl PartialEq for RunnerSnapshot
impl Eq for RunnerSnapshot
impl StructuralPartialEq for RunnerSnapshot
Auto Trait Implementations§
impl Freeze for RunnerSnapshot
impl RefUnwindSafe for RunnerSnapshot
impl Send for RunnerSnapshot
impl Sync for RunnerSnapshot
impl Unpin for RunnerSnapshot
impl UnsafeUnpin for RunnerSnapshot
impl UnwindSafe for RunnerSnapshot
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.