[−][src]Enum gen_epub_book::ops::BookElement
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, ":", false).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
Description(PathBuf)
Relative path to file containing the book's description
Required: no
Value: relative path to (X)HTML chunk
Amount: 0-1
Remarks: exclusive with String-Description and Network-Description
StringDescription(String)
Book's description
Required: no
Type: (X-)HTML
Amount: 0-1
Remarks: exclusive with Description and Network-Description
NetworkDescription(Url)
URL of auxilliary file containing the book's description
Required: no
Type: file URL
Amount: 0-1
Remarks: exclusive with Description and String-Description
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]
pub fn parse(
line: &str,
separator: &str,
free_date: bool
) -> Result<Option<BookElement>, Error>
[src]
line: &str,
separator: &str,
free_date: bool
) -> Result<Option<BookElement>, Error>
(Hopefully) get a book element from a descriptor line with a specified separator with the specified rigidness.
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.
If free_date
is true
, in addition to the default RFC3339,
RFC2822 and Unix-timestamp+tt:zz are accepted as correct DateTime
formats.
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", ":", false).is_err()); assert!(BookElement::parse("Date: 1486564218", ":", true).is_err()); assert!(BookElement::parse("Network-Image-Content: http/i.imgur.com/ViQ2WED.jpg", ":", false).is_err());
Not a description/unrecognised key:
assert_eq!(BookElement::parse("# comment", ":", false), Ok(None)); assert_eq!(BookElement::parse("NetworkImage_Content: that was a typo", ":", false), Ok(None)); assert_eq!(BookElement::parse("Content: used colon instead of equal sign ->", "=", false), Ok(None)); assert_eq!(BookElement::parse("Workers all over the world, unite!", ":", false), Ok(None));
Correct:
assert_eq!(BookElement::parse("Name: nabijaczleweli", ":", false), Ok(Some(BookElement::Name("nabijaczleweli".to_string())))); assert_eq!(BookElement::parse("Date = 2017-02-08T15:30:18+01:00", "=", false), Ok(Some(BookElement::Date( DateTime::parse_from_rfc3339("2017-02-08T15:30:18+01:00").unwrap())))); assert_eq!(BookElement::parse("Date = Wed, 08 Feb 2017 15:30:18 +0100", "=", true), Ok(Some(BookElement::Date( DateTime::parse_from_rfc2822("Wed, 08 Feb 2017 15:30:18 +0100").unwrap())))); assert_eq!(BookElement::parse("Language INCREDIBLE COMMUNISM pl", "INCREDIBLE COMMUNISM", false), Ok(Some(BookElement::Language("pl".to_string()))));
pub fn name(&self) -> &'static str
[src]
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 PartialEq<BookElement> for BookElement
[src]
fn eq(&self, other: &BookElement) -> bool
[src]
fn ne(&self, other: &BookElement) -> bool
[src]
impl Ord for BookElement
[src]
fn cmp(&self, other: &BookElement) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl Clone for BookElement
[src]
fn clone(&self) -> BookElement
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Eq for BookElement
[src]
impl PartialOrd<BookElement> for BookElement
[src]
fn partial_cmp(&self, other: &BookElement) -> Option<Ordering>
[src]
fn lt(&self, other: &BookElement) -> bool
[src]
fn le(&self, other: &BookElement) -> bool
[src]
fn gt(&self, other: &BookElement) -> bool
[src]
fn ge(&self, other: &BookElement) -> bool
[src]
impl Debug for BookElement
[src]
impl Display for BookElement
[src]
Format the element in a way that would make it parse()
able again with the default separator without Free Date Format.
impl Hash for BookElement
[src]
Auto Trait Implementations
impl Send for BookElement
impl Sync for BookElement
Blanket Implementations
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
T: From<U>,
type Error = !
try_from
)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> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
impl<Q, K> Equivalent for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,