RunBuilder

Struct RunBuilder 

Source
pub struct RunBuilder<'a, N, F = CliFrontend>
where N: Node, F: Frontend,
{ /* private fields */ }
Expand description

A builder that runs the narrative when it is dropped

Implementations§

Source§

impl<'a, N, F> RunBuilder<'a, N, F>
where N: Node, F: Frontend,

Source

pub fn command<C, G>(self, names: C, command: G) -> Self
where C: CommandNames, G: Fn(&mut Runtime<'_, N, F>) -> Interrupt<N> + 'static,

Add a global command to the Runtime

Global commands can always be entered by the user.

Some examples of global commands might be:

  • save
  • inventory / inv
  • look around
Examples found in repository?
examples/rooms.rs (lines 110-116)
104fn main() {
105    run(
106        Room::Start,
107        &mut State { has_key: false },
108        &mut CliFrontend::new(),
109    )
110    .command("save", |rt| {
111        match rt.save("rooms.yaml") {
112            Ok(_) => rt.println("Save complete"),
113            Err(e) => rt.println(format!("Error: {}", e)),
114        }
115        Continue
116    })
117    .command("load", |rt| {
118        match rt.load("rooms.yaml") {
119            Ok(_) => rt.println("Load complete"),
120            Err(e) => rt.println(format!("Error: {}", e)),
121        }
122        Skip
123    })
124    .command("inv, inventory", |rt| rt.push_node(Inventory));
125}

Trait Implementations§

Source§

impl<'a, N, F> Drop for RunBuilder<'a, N, F>
where N: Node, F: Frontend,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, N, F> Freeze for RunBuilder<'a, N, F>
where N: Freeze, <N as Node>::State: Freeze, F: Freeze,

§

impl<'a, N, F = CliFrontend> !RefUnwindSafe for RunBuilder<'a, N, F>

§

impl<'a, N, F = CliFrontend> !Send for RunBuilder<'a, N, F>

§

impl<'a, N, F = CliFrontend> !Sync for RunBuilder<'a, N, F>

§

impl<'a, N, F> Unpin for RunBuilder<'a, N, F>
where N: Unpin, <N as Node>::State: Unpin, F: Unpin,

§

impl<'a, N, F = CliFrontend> !UnwindSafe for RunBuilder<'a, N, F>

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.