1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::ScriptContent;
use crate::StoryData;
use crate::StoryTitle;
use crate::StylesheetContent;
use crate::TwineContent;

/// An enum of the types of content that can be inside a [`Passage`]
///
/// [`Passage`]: struct.Passage.html
#[derive(Debug)]
pub enum PassageContent {
    /// A non-special passage that contains Twine content
    Normal(TwineContent),

    /// A passage that contains the title of the story
    StoryTitle(StoryTitle),

    /// A passage that contains the story data defined by the specification
    StoryData(Option<StoryData>),

    /// A passage that is tagged with `script` and contains a script
    Script(ScriptContent),

    /// A passage that is tagged with `stylesheet` and contains CSS
    Stylesheet(StylesheetContent),
}

impl std::convert::From<TwineContent> for PassageContent {
    fn from(p: TwineContent) -> PassageContent {
        PassageContent::Normal(p)
    }
}

impl std::convert::From<StoryTitle> for PassageContent {
    fn from(t: StoryTitle) -> PassageContent {
        PassageContent::StoryTitle(t)
    }
}

impl std::convert::From<Option<StoryData>> for PassageContent {
    fn from(d: Option<StoryData>) -> PassageContent {
        PassageContent::StoryData(d)
    }
}

impl std::convert::From<StoryData> for PassageContent {
    fn from(d: StoryData) -> PassageContent {
        PassageContent::StoryData(Some(d))
    }
}

impl std::convert::From<ScriptContent> for PassageContent {
    fn from(s: ScriptContent) -> PassageContent {
        PassageContent::Script(s)
    }
}

impl std::convert::From<StylesheetContent> for PassageContent {
    fn from(s: StylesheetContent) -> PassageContent {
        PassageContent::Stylesheet(s)
    }
}