[][src]Struct tweep::Story

pub struct Story {
    pub title: Option<String>,
    pub data: Option<StoryData>,
    pub passages: HashMap<String, TwinePassage>,
    pub scripts: Vec<String>,
    pub stylesheets: Vec<String>,
}

A parsed Twee story

This is the primary interface for tweep. The provided utility functions allow a Twee 3 story to be parsed from a String, a directory or file Path, or a slice of string slices, representing the lines of input. The output is an Output<Result<Story, ErrorList>> which is either the parsed Story or an ErrorList if the parse failed, along with a list of any [Warning]s generated during parsing. The fields in this struct provide access to all necessary components of the parsed story.

Parse Errors

  • BadInputPath - The given Path cannot be used to parse a story See Passage for other errors that can occur during parsing

Parse Warnings

Examples

use tweep::Story;
let input = r#":: StoryTitle
RustDoc Sample Story

:: StoryData
{
 "ifid": "D674C58C-DEFA-4F70-B7A2-27742230C0FC",
 "format": "SugarCube",
 "format-version": "2.28.2",
 "start": "My Starting Passage",
 "tag-colors": {
   "tag1": "green",
   "tag2": "red",
   "tag3": "blue"
 },
 "zoom": 0.25
}

:: My Starting Passage [ tag1 tag2 ]
This is the starting passage, specified by the start attribute of StoryData.
Alternately, we could remove that attribute and rename the passage to Start.

It has tags and links to:
 [[Another passage]]
 [[Here too!|Another passage]]
 [[A third passage<-And a different passage]]

:: Another passage {"position":"600,400","size":"100,200"}
This passage has some metadata attached to it

:: A third passage [tag3] { "position": "400,600" }
This passage has both tags and metadata. The size attribute of the metadata
isn't overridden, so it will be set to the default value.
"#.to_string();

let out = Story::from_string(input);
assert!(!out.has_warnings());

let (res, _) = out.take();
assert!(res.is_ok());

let story = res.ok().unwrap();

assert_eq!(story.title.unwrap(), "RustDoc Sample Story");
assert_eq!(story.data.unwrap().ifid, "D674C58C-DEFA-4F70-B7A2-27742230C0FC");

assert_eq!(story.passages["My Starting Passage"].tags(), &vec!["tag1", "tag2"]);
let metadata = story.passages["A third passage"].metadata();
assert_eq!(metadata["size"], "100,100");
assert_eq!(metadata["position"], "400,600");

Fields

title: Option<String>

The story title

data: Option<StoryData>

The story data as defined by the specification

passages: HashMap<String, TwinePassage>

Map from passage name to TwinePassage for any non-special passages

scripts: Vec<String>

A list of the contents of any passages tagged with script

stylesheets: Vec<String>

A list of the contents of any passages tagged with stylesheet

Implementations

impl Story[src]

pub fn from_string(input: String) -> Output<Result<Story, ErrorList>>[src]

Parses an input String and returns the result or a list of errors, along with a list of any Warnings

pub fn from_path<P: AsRef<Path>>(input: P) -> Output<Result<Story, ErrorList>>[src]

Parses a Story from the given Path. If the given path is a file, parses that file and returns the Story. If it is a directory, it looks for any files with .tw or .twee extensions and parses them. Returns the parsed output or a list of errors, along with a list of any Warnings

pub fn from_paths<P: AsRef<Path>>(
    input: &[P]
) -> Output<Result<Story, ErrorList>>
[src]

Parses a Story from the given Paths. See from_path for additional information on how directories are handled.

pub fn get_start_passage_name(&self) -> Option<&str>[src]

If a start passage is configured in the StoryData, return the name of that passage. If no start passage is configured, check for the presence of a passage called "Start". If that passage exists, return that name, otherwise return None

Trait Implementations

impl Default for Story[src]

impl From<StoryPassages> for Story[src]

Auto Trait Implementations

impl !RefUnwindSafe for Story

impl !Send for Story

impl !Sync for Story

impl Unpin for Story

impl UnwindSafe for Story

Blanket Implementations

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

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

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

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

impl<T, U> Into<U> for T where
    U: From<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.