Enum gen_epub_book::ops::BookElement [] [src]

pub enum BookElement {
    Name(String),
    Content(PathBuf),
    StringContent(String),
    ImageContent(PathBuf),
    NetworkImageContent(Url),
    Cover(PathBuf),
    NetworkCover(Url),
    Include(PathBuf),
    NetworkInclude(Url),
    Author(String),
    Date(DateTime<FixedOffset>),
    Language(String),
}

A single element of the e-book

Parse a single line with BookElement::parse() or the whole descriptor with ops::parse_descriptor().

Use Display to desugar back to description form.

Examples

let input = "Image-Content: images/ch01.png";
assert_eq!(&BookElement::parse(input, ":").unwrap().unwrap().to_string(), input);

Variants

E-book's title

Required: yes
Type: plaintext
Amount: 1

Content to put in the e-book

The content is additionally parsed in search for the text chunk containing <!-- ePub title: "TOC_NAME" -->, where TOC_NAME is any string not containing the " character.

That string will be used as the TOC name of the content, which will allow users on e-book readers to jump directly to the content represented by the document containing this entry.

Required: no
Value: relative path to (X)HTML chunk
Amount: any

(X)HTML string to use as content

Required: no
Value: (X)HTML string
Amount: any

Relative path to image to include in e-book

Required: no
Type: file path
Amount: any

URL of image to include in e-book

Required: no
Type: file URL
Amount: any

Relative path to image to use as e-book cover

Required: no
Type: file path
Amount: 0-1
Remarks: exclusive with Network-Cover

URL of image to use as e-book cover

Required: no
Type: file URL
Amount: 0-1
Remarks: exclusive with Cover

Auxilliary file to include in e-book

This is useful for, e.g., CSS.

Required: no
Value: relative path to (X)HTML chunk
Amount: any

URL of auxilliary file to include in e-book

This is useful for, e.g., fonts.

Required: no
Type: file URL
Amount: any

E-book's author

Required: yes
Type: plaintext string
Amount: 1

E-book's authoring/publishing date

Required: yes
Type: RFC3339-compliant date
Amount: 1

Language used in e-book

Required: yes
Type: BCP47-compliant language code
Amount: 1

Methods

impl BookElement
[src]

(Hopefully) get a book element from a descriptor line with a specified separator.

If the line isn't a descripting line or the line uses an unknown key, Ok(None) is returned.

Err will only be returned when parsing a DateTime or a Url fails.

Any whitespace from both parts of the description line are stripped.

Examples

Incorrect format:

assert!(BookElement::parse("Date: Mon, 26 Dec 2016 02:01:20 +0100", ":").is_err());
assert!(BookElement::parse("Network-Image-Content: http/i.imgur.com/ViQ2WED.jpg",
                           ":").is_err());

Not a description/unrecognised key:

assert_eq!(BookElement::parse("# comment", ":"), Ok(None));
assert_eq!(BookElement::parse("NetworkImage_Content: that was a typo", ":"), Ok(None));
assert_eq!(BookElement::parse("Content: used colon instead of equal sign ->", "="),
           Ok(None));
assert_eq!(BookElement::parse("Workers all over the world, unite!", ":"), Ok(None));

Correct:

assert_eq!(BookElement::parse("Name: nabijaczleweli", ":"),
           Ok(Some(BookElement::Name("nabijaczleweli".to_string()))));
assert_eq!(BookElement::parse("Date = 2017-02-08T15:30:18+01:00", "="),
           Ok(Some(BookElement::Date(
             DateTime::parse_from_rfc3339("2017-02-08T15:30:18+01:00").unwrap()))));
assert_eq!(BookElement::parse("Language INCREDIBLE COMMUNISM pl", "INCREDIBLE COMMUNISM"),
           Ok(Some(BookElement::Language("pl".to_string()))));

Get the descriptor name of this element.

Examples

assert_eq!(BookElement::Name("nabijaczleweli".to_string()).name(), "Name");
assert_eq!(BookElement::Content(PathBuf::from("content/ch01.html")).name(), "Content");
assert_eq!(BookElement::NetworkImageContent(
               Url::parse("http://i.imgur.com/ViQ2WED.jpg").unwrap()).name(),
           "Network-Image-Content");

Trait Implementations

impl Clone for BookElement
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for BookElement
[src]

Formats the value using the given formatter.

impl Hash for BookElement
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl PartialEq for BookElement
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for BookElement
[src]

impl PartialOrd for BookElement
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Ord for BookElement
[src]

This method returns an Ordering between self and other. Read more

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the maximum of two values. Read more

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the minimum of two values. Read more

impl Display for BookElement
[src]

Format the element in a way that would make it parse()able again with the default separator.

Formats the value using the given formatter. Read more