Expand description
Runtime/VM for executing compiled ink stories.
The runtime takes a StoryData from the compiler,
links it into an immutable Program, and executes it via Story.
ⓘ
use std::sync::Arc;
let (program, line_tables) = brink_runtime::link(&story_data)?;
let mut story = brink_runtime::Story::new(Arc::new(program), line_tables);
loop {
match story.continue_single()? {
Line::Text { text, .. } => print!("{text}"),
Line::Choices { text, choices, .. } => {
print!("{text}");
// pick a choice...
story.choose(0)?;
}
Line::End { text, .. } => {
print!("{text}");
break;
}
}
}Re-exports§
Modules§
- rng
- Pluggable PRNG for story randomization.
- transcript
- Transcript binary serialization (
.brktformat).
Structs§
- Budget
- Caller-supplied cap on a
Speculation’s VM stepping, in place of the runtime’s hardcodedSTEP_LIMIT/LINE_LIMITceilings. - Choice
- A single choice presented to the player.
- Context
View - Routing view implementing
ContextAccessover(&mut World, &mut FlowLocal). - Debug
Choice - A pending choice and the knot it targets.
- Debug
Frame - One call frame, resolved to a knot/stitch path.
- Debug
Global - A global variable and its current value.
- Debug
Rng - Story RNG state.
- Debug
Snapshot - A structured, read-only snapshot of the runtime’s current state.
- Debug
Visit - A visit count for a named knot/stitch.
- Externals
Report - Diagnostic record of which externals a
KindTieredHandlerlet through live versus fell back, across the handler’s lifetime. - Fallback
Handler - Default handler that always falls back to the ink function body.
- Flow
Instance - A single independent execution context within a story. The default flow
runs from the root container; named flows can be spawned at arbitrary
entry points via
FlowInstance::new_at. - Flow
Local - Per-flow override layer over the shared
World. - Fragment
- A finalized fragment — structural output parts plus any associated tags.
- Journal
Event - One input that entered the VM.
- Kind
Tiered Handler - A stackable
ExternalFnHandlerthat tiers externals byPolicyKindbefore delegating to a real handler. - List
Delta - Membership delta for one list-valued global.
- List
Member - One active member of a list value, resolved for host-facing display. See
Program::list_members. - Load
Report - What
Story::load_statecouldn’t apply, so a host can surface it rather than have data silently vanish. Globals whose name no longer exists are dropped (no slot to hold them) and reported here. Visit/turn counts are never dropped — counts for scopes the current program lacks are retained harmlessly (unused until/unless the scope returns), so they aren’t reported. - Observed
Context - A
ContextAccesswrapper that delegates to an innerContextAccessimplementor (typicallyWorldor theContextViewrouting view) and notifies aWriteObserveron every mutation. - Program
- A linked, ready-to-execute program.
- Recorded
External - One recorded external-function result, captured in call order during a live run.
- Recording
Handler - Wraps an
ExternalFnHandlerand records every inline-Resolvedexternal result into aReplayRecorderduring a live run. - Replay
Handler - Replays recorded external results (
ReplayMode::Recorded). - Replay
Recorder - An append-only, capped log of external results for one flow, plus a replay cursor. Recorded during the live run; consumed in order during replay.
- Resolved
Policy - Fast, id/slot-based resolution of a
WorldPolicyagainst a specificProgram. Built once atWorldcreation viaResolvedPolicy::resolve; consulted on every state access (from F2.2 on) with O(1) lookups — no string matching on the hot path. - Save
State - A persistent, name-keyed snapshot of a story’s game state.
- Session
Journal - One ordered log of every input that entered the VM during a session, plus a
terminal fast-restore
checkpoint. - Snapshot
Frame - One summarized call frame.
- Snapshot
List - Resolved membership of a
List-valued global. - Speculation
- A sandboxed, self-contained speculative run over a story’s current state. See the module docs for the full picture.
- State
Diff - A pure diff between two
StateSnapshots (seediff). - State
Snapshot - A typed, name-resolved snapshot of a session’s game state.
- Stats
- Lightweight counters tracking VM activity over a story’s lifetime.
- Story
- Per-instance mutable state for executing stories.
- Story
Session - A journaling, replayable session wrapping a
Story. - Story
Snapshot - Owned story state that can be detached from a
Programand reattached later. - Visit
Entry - One visit/turn-count entry: a scope id and its count, plus (when the scope
is a named knot/stitch) an advisory author path for human inspection. The
idis the load key;pathis cosmetic. - World
- Shared game state that lives above individual flows.
- World
Policy - Host-facing, name-based declaration of the world/local split.
Enums§
- Commit
Error - Errors from
commit. - Divergence
Found - What was found at a divergence point instead of the recorded event.
- Drive
Outcome - Outcome of a single
FlowInstance::drivecall: either the drive reached a terminal line, or it paused on a deferred external mid-drive. Both variants carry everyLineproduced during this call — forAwaitingExternal, that’s the (possibly empty) run ofLine::Textproduced before the pause; forTerminal, the terminal line is always the last element (seeFlowInstance::drive). - Eval
Context - Which evaluation regime a
KindTieredHandleris gating for. - Event
Kind - The kind + payload of a
JournalEvent. - External
Replay Mode - How replay obtains external values.
- External
Result - Result of an external function handler call.
- Fail
Reason - Why replay stopped without diverging.
- Function
Eval - Outcome of an engine→ink function evaluation
(
FlowInstance::begin_function_eval/resume_function_eval). - Line
- A single step of story output from
Story::continue_single. - Locale
Mode - Controls how missing scopes are handled when applying a locale overlay.
- Mode
- Execution mode of a
FlowLocal, baked in at construction/fork time and read byContextViewto decide how it routes every unit. - Output
Part - A part of accumulated output.
- Policy
Error - Errors resolving a
WorldPolicyagainst aProgram’s symbol table. - Policy
Kind - The effect category a
KindTieredHandlergates on. Plain data — the consumer maps its own (richer) external classification onto this two-way split. - Replay
Mode - How a replay obtains external values. Whole-flow granularity.
- Replay
Outcome - Outcome of replaying a journal prefix against a program.
- Replay
Warning - A non-fatal replay observation.
- Runtime
Error - Errors that can occur during story linking or execution.
- Scope
- Where a unit of story-state lives: the shared
Worldor a flow’s privateFlowLocal. - Session
Error - Errors from session-level operations (distinct from VM
RuntimeErrors, which are wrapped). - Snapshot
Status - Session execution status, serde-friendly.
- Speculation
Step - Outcome of a single
Speculation::advancecall. - Step
Outcome - Outcome of a single
FlowInstance::advancestep. - Story
Status - The current execution status of a story.
Constants§
- RECORDING_
CAP - Upper bound on recorded externals per flow (unbounded-growth guard). Beyond
it,
ReplayRecorder::recorddrops the result and replay falls through to the ink fallback body for the uncovered tail. - SAVE_
FORMAT_ VERSION - Current
SaveStateformat version. Bump when the format changes (independent of the story’s own content);versionlets a loader migrate. - SESSION_
JOURNAL_ CAP - Upper bound on journal events (unbounded-growth guard, mirroring
RECORDING_CAP). Beyond it, appends are dropped andSessionJournal::truncatedis set — the journal degrades honestly and restore falls back to the embeddedcheckpoint. - SESSION_
JOURNAL_ VERSION - Current
SessionJournalformat version.
Traits§
- Context
Access - Trait for accessing and mutating story execution state.
- External
FnHandler - Trait for handling external function calls from ink.
- Write
Observer - Observer for state mutations during story execution.
Functions§
- apply_
locale - Apply a locale overlay to a set of base line tables.
- commit
- Fold a forked child’s own-layer overrides back into its parent’s,
making the child’s writes visible through
parent(and, transitively, anythingparentitself chains to or is later written through). - diff
- Pure diff of two snapshots.
ais “before”,bis “after”. - link
- Link a
StoryDatainto an executableProgram. - load_
state - Reconcile a
SaveStateinto a flow’s context, returning aLoadReportof anything that couldn’t be applied. Globals are matched by name; visit/turn counts by id. Tolerant of story patches: unknown globals are reported, scopes the program no longer has retain their saved counts harmlessly in the live context. Note one deliberate change from the pre-F6.1bStorymethods: such stale entries are not re-emitted by a subsequentsave_state(which enumerates the current program’s containers, not the live maps) — ghost counts from older program versions no longer round-trip through saves indefinitely. - save_
state - Capture a flow’s game state as a durable, name-keyed
SaveState. Does not capture execution position — see the module docs.