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
Name(String)
E-book's title
Required: yes
Type: plaintext
Amount: 1
Content(PathBuf)
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
StringContent(String)
(X)HTML string to use as content
Required: no
Value: (X)HTML string
Amount: any
ImageContent(PathBuf)
Relative path to image to include in e-book
Required: no
Type: file path
Amount: any
NetworkImageContent(Url)
URL of image to include in e-book
Required: no
Type: file URL
Amount: any
Cover(PathBuf)
Relative path to image to use as e-book cover
Required: no
Type: file path
Amount: 0-1
Remarks: exclusive with Network-Cover
NetworkCover(Url)
URL of image to use as e-book cover
Required: no
Type: file URL
Amount: 0-1
Remarks: exclusive with Cover
Include(PathBuf)
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
NetworkInclude(Url)
URL of auxilliary file to include in e-book
This is useful for, e.g., fonts.
Required: no
Type: file URL
Amount: any
Author(String)
E-book's author
Required: yes
Type: plaintext string
Amount: 1
Date(DateTime<FixedOffset>)
E-book's authoring/publishing date
Required: yes
Type: RFC3339-compliant date
Amount: 1
Language(String)
Language used in e-book
Required: yes
Type: BCP47-compliant language code
Amount: 1
Methods
impl BookElement
[src]
fn parse(line: &str, separator: &str) -> Result<Option<BookElement>, Error>
(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()))));
fn name(&self) -> &'static str
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]
fn clone(&self) -> BookElement
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for BookElement
[src]
impl Hash for BookElement
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialEq for BookElement
[src]
fn eq(&self, __arg_0: &BookElement) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &BookElement) -> bool
This method tests for !=
.
impl Eq for BookElement
[src]
impl PartialOrd for BookElement
[src]
fn partial_cmp(&self, __arg_0: &BookElement) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &BookElement) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &BookElement) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &BookElement) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &BookElement) -> bool
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]
fn cmp(&self, __arg_0: &BookElement) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
ord_max_min
)Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
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.