Skip to main content

DialogueVm

Struct DialogueVm 

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

Runs one Dialogue, one event at a time.

Create it with Default, then alternate start and resume as described in the module documentation. The same VM can be reused for another run, or another node, once the current dialogue is finished.

A DialogueVm holds the Dialogue at start but can be changed each time a start is called.

Implementations§

Source§

impl DialogueVm

Source

pub fn start( &mut self, dialogue: Dialogue, name: impl Into<NodeName>, ) -> Result<DialogueEvent, VmError>

Same as DialogueVm::start_with but with NoHost as host.

Source

pub fn start_with<H: RepliqueHost>( &mut self, host: &mut H, dialogue: Dialogue, name: impl Into<NodeName>, ) -> Result<DialogueEvent, VmError>

Start dialogue at the node name and run up to the first event.

The caller give a RepliqueHost to give access to its registered functions.

Fails with VmError::DialogueNotFinished if a run is still in progress, and with VmError::DialogueNodeNotFound if the node does not exist. Starting again after DialogueEvent::Finished is fine and resets the VM.

Source

pub fn vars(&self) -> &VarStore

Every variable the dialogue has written, and its value. Use for tests

Source

pub fn resume(&mut self, resume: ResumeEvent) -> Result<DialogueEvent, VmError>

Same as DialogueVm::resume_with but with NoHost as host.

Source

pub fn resume_with<H: RepliqueHost>( &mut self, host: &mut H, resume: ResumeEvent, ) -> Result<DialogueEvent, VmError>

Answer the last DialogueEvent and run up to the next one.

The caller give a RepliqueHost to give access to its registered functions.

resume must match the event the VM emitted, see ResumeEvent. On error the VM stays suspended where it was, so a wrong or out of range answer can just be retried.

Trait Implementations§

Source§

impl Default for DialogueVm

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.