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//! ```no_run
7//! # fn example(story_data: &brink_format::StoryData) -> Result<(), brink_runtime::RuntimeError> {
8//! use std::sync::Arc;
9//! use brink_runtime::Step;
10//!
11//! let (program, line_tables) = brink_runtime::link(story_data)?;
12//! let mut story: brink_runtime::Story = brink_runtime::Story::new(Arc::new(program), line_tables);
13//! loop {
14//!     match story.continue_single()? {
15//!         Step::Line(line) => print!("{}", line.text),
16//!         Step::Done => {}
17//!         Step::Choices(choices) => {
18//!             let _ = choices;
19//!             // pick a choice...
20//!             story.choose(0)?;
21//!         }
22//!         Step::End => break,
23//!         Step::Suspended => break,
24//!     }
25//! }
26//! # Ok(())
27//! # }
28//! ```
29//!
30//! `no_std` + `alloc`: this crate builds without the standard library when
31//! the default `std` feature is disabled (see `docs/no-std-portability.md`).
32#![cfg_attr(not(feature = "std"), no_std)]
33
34extern crate alloc;
35
36#[cfg(feature = "bench-counters")]
37pub mod bench_counters;
38mod collection_ops;
39mod collections;
40mod conversion_ops;
41mod debug;
42#[cfg(feature = "effect-trace")]
43pub mod effect_trace;
44mod error;
45mod external_policy;
46mod iter;
47mod linker;
48mod list_ops;
49mod locale;
50mod output;
51mod program;
52mod proj_ops;
53mod rand_ops;
54mod range_ops;
55mod record_ops;
56mod replay;
57pub mod rng;
58mod save;
59mod session;
60mod speculation;
61mod state;
62mod story;
63mod string_ops;
64mod tower_ops;
65pub mod transcript;
66mod value_ops;
67mod vm;
68mod world;
69
70pub use brink_format::{LoadReport, SAVE_FORMAT_VERSION, SaveState, VisitEntry};
71pub use debug::{DebugChoice, DebugFrame, DebugGlobal, DebugRng, DebugSnapshot, DebugVisit};
72pub use error::{RanOutOfContentCause, RuntimeError};
73pub use external_policy::{EvalContext, ExternalsReport, KindTieredHandler, PolicyKind};
74pub use iter::ValueIter;
75pub use linker::link;
76pub use locale::{LocaleMode, apply_locale};
77pub use output::{Fragment, OutputPart};
78pub use program::{ListMember, Program};
79pub use replay::{
80    RECORDING_CAP, RecordedExternal, RecordingHandler, ReplayHandler, ReplayMode, ReplayRecorder,
81};
82pub use rng::{DotNetRng, FastRng, StoryRng};
83pub use save::{load_state, save_state};
84pub use session::{
85    DivergenceFound, EventKind, ExternalReplayMode, FailReason, JournalEvent, ListDelta,
86    ReplayOutcome, ReplayWarning, SESSION_JOURNAL_CAP, SESSION_JOURNAL_VERSION, SessionError,
87    SessionJournal, SnapshotFrame, SnapshotList, SnapshotStatus, StateDiff, StateSnapshot,
88    StorySession, diff,
89};
90pub use speculation::{Budget, Speculation, SpeculationStep};
91pub use state::{ContextAccess, ObservedContext, WriteObserver};
92pub use story::{
93    BlockId, Choice, DriveOutcome, Element, ExecMode, ExternalFnHandler, ExternalResult,
94    FallbackHandler, FlowInstance, FunctionEval, OutputLine, Stats, Step, StepOutcome, Story,
95    StorySnapshot, StoryStatus,
96};
97pub use world::{
98    CommitError, ContextView, FlowLocal, FrameStartView, Mode, PolicyError, ResolvedPolicy, Scope,
99    World, WorldPolicy, commit,
100};