Struct gen_epub_book::ops::EPubBook
[−]
[src]
pub struct EPubBook { pub name: String, pub author: String, pub date: DateTime<FixedOffset>, pub language: String, pub cover: Option<EPubData>, // some fields omitted }
Full ePub book, bundled together.
Fields
name: String
E-book's title
E-book's author
date: DateTime<FixedOffset>
E-book's authoring/publishing date
language: String
Language used in e-book
cover: Option<EPubData>
Image to use as e-book cover, if any
Methods
impl EPubBook
[src]
fn from_elements<E: IntoIterator<Item = BookElement>>(
elems: E
) -> Result<EPubBook, Error>
elems: E
) -> Result<EPubBook, Error>
Construct a book from loose elements
Returns an error upon violating any of the requirements laid forth in the variants of BookElement
.
Examples
let book = EPubBook::from_elements(vec![ BookElement::Name("Simple ePub demonstration".to_string()), BookElement::Cover(PathBuf::from("examples/cover.png")), BookElement::ImageContent(PathBuf::from("examples/simple/chapter_image.png")), BookElement::Content(PathBuf::from("examples/simple/ctnt.html")), BookElement::Author("nabijaczleweli".to_string()), BookElement::Date(DateTime::parse_from_rfc3339("2017-02-08T15:30:18+01:00").unwrap()), BookElement::Language("en-GB".to_string()), ]).unwrap(); assert_eq!(book.name, "Simple ePub demonstration".to_string()); assert_eq!(book.author, "nabijaczleweli".to_string()); assert_eq!(book.date, DateTime::parse_from_rfc3339("2017-02-08T15:30:18+01:00").unwrap()); assert_eq!(book.language, "en-GB".to_string()); assert_eq!(book.cover, Some(("cover-content-1".to_string(), PathBuf::from("cover-data-1.html"), EPubContentType::Raw("<center>\ <img src=\"examples-cover.png\" \ alt=\"examples-cover.png\"></img>\ </center>".to_string()))));
fn normalise_paths<W: Write>(
&mut self,
relroot: &[IncludeDirectory],
verbose: bool,
verb_out: &mut W
) -> Result<(), Error>
&mut self,
relroot: &[IncludeDirectory],
verbose: bool,
verb_out: &mut W
) -> Result<(), Error>
Normalise the paths in the book based on the specified relative path root, optionally printing verbose output to the specified stream.
Will return an error if the file the path points to doesn't exist or isn't a file.
Examples
let mut book = EPubBook::from_elements(vec![ BookElement::Name("Path normalisation demonstration".to_string()), BookElement::Cover(PathBuf::from("cover.png")), BookElement::Content(PathBuf::from("content/ch01.html")), BookElement::Author("nabijaczleweli".to_string()), BookElement::Date(DateTime::parse_from_rfc3339("2017-02-08T15:30:18+01:00").unwrap()), BookElement::Language("en-GB".to_string()), ]).unwrap(); book.normalise_paths(&["./".parse().unwrap()], false, &mut stdout()).unwrap(); assert_eq!(book.cover, Some(("cover".to_string(), PathBuf::from("cover.png"), EPubContentType::File( PathBuf::from("cover.png").canonicalize().unwrap()))));
fn write_zip<W: Write + Seek, V: Write>(
&self,
to: &mut W,
verbose: bool,
verb_out: &mut V
) -> Result<(), Error>
&self,
to: &mut W,
verbose: bool,
verb_out: &mut V
) -> Result<(), Error>
Write the book as ePub into the specified stream, optionally logging verbose output.
Examples
let mut book = EPubBook::from_elements(vec![ BookElement::Name("Path normalisation demonstration".to_string()), BookElement::Cover(PathBuf::from("cover.png")), BookElement::Content(PathBuf::from("content/ch01.html")), BookElement::Author("nabijaczleweli".to_string()), BookElement::Date(DateTime::parse_from_rfc3339("2017-02-08T15:30:18+01:00").unwrap()), BookElement::Language("en-GB".to_string()), ]).unwrap(); book.normalise_paths(&["./".parse().unwrap()], false, &mut stdout()).unwrap(); book.write_zip(&mut File::create("write_zip.epub").unwrap(), false, &mut stdout()).unwrap();
Trait Implementations
impl Clone for EPubBook
[src]
fn clone(&self) -> EPubBook
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 EPubBook
[src]
impl Hash for EPubBook
[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 EPubBook
[src]
fn eq(&self, __arg_0: &EPubBook) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &EPubBook) -> bool
This method tests for !=
.
impl Eq for EPubBook
[src]
impl PartialOrd for EPubBook
[src]
fn partial_cmp(&self, __arg_0: &EPubBook) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &EPubBook) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &EPubBook) -> 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: &EPubBook) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &EPubBook) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Ord for EPubBook
[src]
fn cmp(&self, __arg_0: &EPubBook) -> 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