[−][src]Struct tweep::Story
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 givenPath
cannot be used to parse a story SeePassage
for other errors that can occur during parsing
Parse Warnings
DuplicateStoryTitle
- More than oneStoryTitle
passage foundDuplicateStoryData
- More than oneStoryData
passage foundMissingStoryTitle
- NoStoryTitle
passage foundMissingStoryData
- NoStoryData
passage foundDeadLink
- Found a link to a non-existent passageMissingStartPassage
- NoStart
passage found and no alternate passage set inStoryData
DeadStartPassage
- Alternate start passage set inStoryData
, but no such passage found in parsing SeePassage
for other warnings that can occur during parsing
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, Passage>
Map from passage name to Passage
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
Methods
impl Story
[src]
pub fn from_string(input: String) -> Output<Result<Self, ErrorList>>
[src]
Parses an input String
and returns the result or a list of errors,
along with a list of any Warning
s
pub fn from_slice(input: &[&str]) -> Output<Result<Self, ErrorList>>
[src]
Parses an input &[&str]
and returns the result or a list of errors,
along with a list of any Warning
s
pub fn from_path<P: AsRef<Path>>(input: P) -> Output<Result<Self, ErrorList>>
[src]
Trait Implementations
impl Default for Story
[src]
impl From<StoryPassages> for Story
[src]
fn from(s: StoryPassages) -> 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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,