Skip to main content

RunnerBuilder

Struct RunnerBuilder 

Source
pub struct RunnerBuilder<S: VariableStorage> { /* private fields */ }
Expand description

Builds a Runner with optional saliency, provider, and host-function configuration in a single fluent chain.

Use this when you need to customise at least one of those at construction time; for the zero-config case Runner::new is still the fastest path.

§Example

use bubbles::{HashMapStorage, RunnerBuilder, Value, compile};
use bubbles::saliency::BestLeastRecentlyViewed;

let prog = compile("title: A\n---\nHello.\n===\n").unwrap();
let mut runner = RunnerBuilder::new(prog, HashMapStorage::new())
    .with_saliency(BestLeastRecentlyViewed::default())
    .with_function("greet", |_args| Ok(Value::Text("hi".into())))
    .build();
runner.start("A").unwrap();

Implementations§

Source§

impl<S: VariableStorage> RunnerBuilder<S>

Source

pub fn new(program: Program, storage: S) -> Self

Creates a builder with defaults matching Runner::new: FirstAvailable saliency and PassthroughProvider.

Source

pub fn with_saliency(self, strategy: impl SaliencyStrategy) -> Self

Overrides the saliency strategy used for line and node group selection.

Source

pub fn with_provider(self, provider: impl LineProvider) -> Self

Overrides the line provider used for localisation lookup.

Source

pub fn with_function<F>(self, name: &str, f: F) -> Self
where F: Fn(Vec<Value>) -> Result<Value> + Send + Sync + 'static,

Registers a host function available to dialogue expressions.

This is a convenience wrapper around FunctionLibrary::register that keeps configuration on the builder rather than requiring a post-construction library_mut() call.

Source

pub fn build(self) -> Runner<S>

Consumes the builder and returns a fully configured Runner.

The runner is in the Idle state; call Runner::start to begin execution.

Auto Trait Implementations§

§

impl<S> Freeze for RunnerBuilder<S>
where S: Freeze,

§

impl<S> !RefUnwindSafe for RunnerBuilder<S>

§

impl<S> Send for RunnerBuilder<S>
where S: Send,

§

impl<S> Sync for RunnerBuilder<S>
where S: Sync,

§

impl<S> Unpin for RunnerBuilder<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for RunnerBuilder<S>
where S: UnsafeUnpin,

§

impl<S> !UnwindSafe for RunnerBuilder<S>

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> 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, 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.