Skip to main content

brink_runtime/
lib.rs

1//! Runtime/VM for executing compiled ink stories.
2//!
3//! The runtime takes a [`StoryData`](brink_format::StoryData) from the compiler,
4//! links it into an immutable [`Program`], and executes it via [`Story`].
5//!
6//! ```ignore
7//! use std::sync::Arc;
8//!
9//! let (program, line_tables) = brink_runtime::link(&story_data)?;
10//! let mut story = brink_runtime::Story::new(Arc::new(program), line_tables);
11//! loop {
12//!     match story.continue_single()? {
13//!         Line::Text { text, .. } => print!("{text}"),
14//!         Line::Choices { text, choices, .. } => {
15//!             print!("{text}");
16//!             // pick a choice...
17//!             story.choose(0)?;
18//!         }
19//!         Line::End { text, .. } => {
20//!             print!("{text}");
21//!             break;
22//!         }
23//!     }
24//! }
25//! ```
26
27mod debug;
28mod error;
29mod external_policy;
30mod linker;
31mod list_ops;
32mod locale;
33mod output;
34mod program;
35mod replay;
36pub mod rng;
37mod save;
38mod session;
39mod speculation;
40mod state;
41mod story;
42pub mod transcript;
43mod value_ops;
44mod vm;
45mod world;
46
47pub use brink_format::{LoadReport, SAVE_FORMAT_VERSION, SaveState, VisitEntry};
48pub use debug::{DebugChoice, DebugFrame, DebugGlobal, DebugRng, DebugSnapshot, DebugVisit};
49pub use error::RuntimeError;
50pub use external_policy::{EvalContext, ExternalsReport, KindTieredHandler, PolicyKind};
51pub use linker::link;
52pub use locale::{LocaleMode, apply_locale};
53pub use output::{Fragment, OutputPart};
54pub use program::{ListMember, Program};
55pub use replay::{
56    RECORDING_CAP, RecordedExternal, RecordingHandler, ReplayHandler, ReplayMode, ReplayRecorder,
57};
58pub use rng::{DotNetRng, FastRng, StoryRng};
59pub use save::{load_state, save_state};
60pub use session::{
61    DivergenceFound, EventKind, ExternalReplayMode, FailReason, JournalEvent, ListDelta,
62    ReplayOutcome, ReplayWarning, SESSION_JOURNAL_CAP, SESSION_JOURNAL_VERSION, SessionError,
63    SessionJournal, SnapshotFrame, SnapshotList, SnapshotStatus, StateDiff, StateSnapshot,
64    StorySession, diff,
65};
66pub use speculation::{Budget, Speculation, SpeculationStep};
67pub use state::{ContextAccess, ObservedContext, WriteObserver};
68pub use story::{
69    Choice, DriveOutcome, ExternalFnHandler, ExternalResult, FallbackHandler, FlowInstance,
70    FunctionEval, Line, Stats, StepOutcome, Story, StorySnapshot, StoryStatus,
71};
72pub use world::{
73    CommitError, ContextView, FlowLocal, Mode, PolicyError, ResolvedPolicy, Scope, World,
74    WorldPolicy, commit,
75};