[][src]Struct inkling::Story

pub struct Story { /* fields omitted */ }

Story with knots, diverts, choices and possibly lots of text.

Methods

impl Story[src]

pub fn start(
    &mut self,
    line_buffer: &mut LineBuffer
) -> Result<Prompt, InklingError>
[src]

Start walking through the story while reading all lines into the supplied buffer. Returns either when the story reached an end or when a set of choices was encountered, which requires the user to select one. Continue the story with resume_with_choice.

Notes

The input line buffer is not cleared before reading new lines into it.

Examples

let content = "\
Only in silence the word,
only in dark the light,
only in dying life:
bright the hawk’s flight
on the empty sky.
";

let mut story: Story = read_story_from_string(content).unwrap();
let mut line_buffer = Vec::new();

story.start(&mut line_buffer);

assert_eq!(line_buffer.last().unwrap().text, "on the empty sky.\n");

pub fn resume_with_choice(
    &mut self,
    choice: &Choice,
    line_buffer: &mut LineBuffer
) -> Result<Prompt, InklingError>
[src]

Resume the story with a choice from the given set.

The story continues until it reaches a dead end or another set of choices is encountered.

Notes

The input line buffer is not cleared before reading new lines into it.

Examples

let content = "\
Just as Nancy picked the old diary up from the table she heard
the door behind her creak open. Someone’s coming!

*   She spun around to face the danger head on.
    Her heart was racing as the door slowly swung open and the black
    cat from the garden swept in.
    “Miao!”   
*   In one smooth motion she hid behind the large curtain.
    A familiar “meow” coming from the room filled her with relief.
    That barely lasted a moment before the dusty curtains made her
    sneeze, awakening the house keeper sleeping in the neighbouring room.
";

let mut story = read_story_from_string(content).unwrap();
let mut line_buffer = Vec::new();

if let Prompt::Choice(choices) = story.start(&mut line_buffer).unwrap() {
    story.resume_with_choice(&choices[0], &mut line_buffer);
}

assert_eq!(line_buffer.last().unwrap().text, "“Miao!”\n");

Trait Implementations

impl Debug for Story[src]

Auto Trait Implementations

impl !Sync for Story

impl Send for Story

impl Unpin for Story

impl !RefUnwindSafe for Story

impl !UnwindSafe for Story

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]