Skip to main content

FlowInstance

Struct FlowInstance 

Source
pub struct FlowInstance { /* private fields */ }
Expand description

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.

A FlowInstance is opaque from outside the crate: its internal fields (flow, status, stats) are crate-private, but consumers can hold, clone, serialize, and pass &mut FlowInstance to the runtime’s step functions. Use the inherent methods (step_single_line, choose, transcript, status, etc.) for all interaction.

Implementations§

Source§

impl FlowInstance

Source

pub fn new_at_root(program: &Program) -> (Self, Context)

Create a new flow instance starting at the program’s root container, along with a fresh Context initialized from the program’s global defaults.

Source

pub fn new_at(program: &Program, container_idx: u32) -> (Self, Context)

Create a new flow instance starting at an arbitrary container index, along with a fresh Context. Use this to spawn a named flow at a specific entry point. The caller is responsible for deciding whether to share the returned Context with other flows or discard it and reuse an existing one.

Source

pub fn step_single_line<R: StoryRng>( &mut self, program: &Program, line_tables: &[Vec<LineEntry>], context: &mut (impl ContextAccess + ?Sized), handler: &dyn ExternalFnHandler, resolver: Option<&dyn PluralResolver>, ) -> Result<Line, RuntimeError>

Execute until one complete line of output is available, or until a yield point (choices/done/ended) if no newline occurs first.

Returns a Line telling the caller what happened (Text/Done/ Choices/End). This is the simple API for consumers whose external handler never defers: if the handler returns ExternalResult::Pending, this errors with UnresolvedExternalCall. For pausable world-access bindings, use advance.

Source

pub fn advance<R: StoryRng>( &mut self, program: &Program, line_tables: &[Vec<LineEntry>], context: &mut (impl ContextAccess + ?Sized), handler: &dyn ExternalFnHandler, resolver: Option<&dyn PluralResolver>, ) -> Result<StepOutcome, RuntimeError>

Like step_single_line, but surfaces a deferred external (ExternalResult::Pending) as StepOutcome::AwaitingExternal instead of an error — so a world-access binding hit during normal playback can pause cleanly. Resolve the pending external and call advance again to continue.

Source

pub fn choose( &mut self, context: &mut (impl ContextAccess + ?Sized), index: usize, ) -> Result<(), RuntimeError>

Select a choice by index. Call step_single_line afterward to continue execution from the chosen branch.

Source

pub fn status(&self) -> StoryStatus

The current execution status of this flow.

Source

pub fn stats(&self) -> &Stats

Runtime statistics (instructions, materialization counts, etc.) accumulated over this flow’s execution.

Source

pub fn transcript(&self) -> &[OutputPart]

The full append-only transcript of all output parts produced so far.

The transcript stores structural references (e.g. LineRef) rather than resolved strings, so it can be re-rendered in any locale by passing a different set of line tables to transcript::render_transcript.

Source

pub fn transcript_len(&self) -> usize

Number of parts in the transcript.

Source

pub fn reset_cursor(&mut self)

Reset the transcript read cursor to the beginning (for re-rendering, e.g. after a locale swap).

Source

pub fn fragments(&self) -> &[Fragment]

The fragments captured during execution (for re-rendering choice display text and computed substrings in a different locale).

Source

pub fn has_pending_external(&self) -> bool

Returns true if this flow is frozen on an unresolved external call — i.e. the VM hit a CallExternal opcode and the handler returned ExternalResult::Pending, leaving the External frame on top of the call stack.

The orchestration layer (e.g. a Bevy resolver system) polls this to decide whether the flow needs an external resolved before it can be driven further. Resolve via resolve_external.

Source

pub fn pending_external_fn_id(&self) -> Option<DefinitionId>

The DefinitionId of the pending external function, if this flow is frozen on one. Returns None otherwise.

Source

pub fn pending_external_args(&self) -> &[Value]

The arguments to the pending external call, in declaration order. Empty if no external call is pending.

Source

pub fn pending_external_name<'p>(&self, program: &'p Program) -> Option<&'p str>

The ink-declared name of the pending external function, resolved against program’s name table. Returns None if no external is pending (or the entry is missing, which would indicate a malformed program).

The orchestration layer uses this to look up the binding registered for this name.

Source

pub fn resolve_external(&mut self, value: Value)

Resolve a pending external call by supplying its return value. Pops the External frame and pushes value onto the value stack so the VM can resume. For fire-and-forget externals, pass Value::Null.

No-op if no external call is pending. After resolving, drive the flow forward with step_single_line.

Source

pub fn begin_function_eval<R: StoryRng>( &mut self, program: &Program, line_tables: &[Vec<LineEntry>], context: &mut (impl ContextAccess + ?Sized), handler: &dyn ExternalFnHandler, container_idx: u32, args: &[Value], resolver: Option<&dyn PluralResolver>, ) -> Result<FunctionEval, RuntimeError>

Evaluate an ink function from engine code, returning its value.

This does not advance the player-visible story: a FunctionEvalFromGame boundary frame is pushed, args are passed in declaration order (exactly as a normal call site would), output is captured and discarded, and the function runs until it returns.

If the function calls an external whose handler returns ExternalResult::Pending (e.g. a binding that needs Bevy World access), evaluation pauses and returns FunctionEval::AwaitingExternal; the caller resolves the external (see resolve_external) and calls resume_function_eval.

container_idx is the function’s container, typically obtained from Program::find_address on the function name. Unlike a normal Call, this does not increment the function’s visit count — an engine query is out-of-band, matching C#’s EvaluateFunction.

§Errors
Source

pub fn resume_function_eval<R: StoryRng>( &mut self, program: &Program, line_tables: &[Vec<LineEntry>], context: &mut (impl ContextAccess + ?Sized), handler: &dyn ExternalFnHandler, resolver: Option<&dyn PluralResolver>, ) -> Result<FunctionEval, RuntimeError>

Resume a function evaluation that paused on FunctionEval::AwaitingExternal, after the pending external has been resolved via resolve_external.

§Errors
Source

pub fn is_evaluating_function(&self) -> bool

Returns true if a function evaluation is in progress (possibly paused awaiting an external).

Trait Implementations§

Source§

impl Clone for FlowInstance

Source§

fn clone(&self) -> FlowInstance

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FlowInstance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.