Skip to main content

TableOfContents

Struct TableOfContents 

Source
pub struct TableOfContents { /* private fields */ }
Expand description

Complete Table of Contents

Implementations§

Source§

impl TableOfContents

Source

pub fn new() -> Self

Source

pub fn add_entry(&mut self, title: String, href: String, level: usize)

Source

pub fn get_entries(&self) -> &[TocEntry]

Examples found in repository?
examples/basic_usage.rs (line 64)
3fn main() {
4    // Example of how to use the epubie-lib library
5    let epub_path = "./example-files/iia.epub";
6
7    println!("Attempting to parse EPUB: {}", epub_path);
8
9    match Epub::new(epub_path.to_string()) {
10        Ok(epub) => {
11            // Display basic metadata
12            println!("\n=== EPUB Metadata ===");
13            println!("Title: {}", epub.get_title());
14            println!("Creator: {}", epub.get_creator());
15            println!("Language: {}", epub.get_language());
16            println!("Identifier: {}", epub.get_identifier());
17            println!("Date: {}", epub.get_date());
18
19            if let Some(publisher) = epub.get_publisher() {
20                println!("Publisher: {}", publisher);
21            }
22
23            if let Some(description) = epub.get_description() {
24                println!("Description: {}", description);
25            }
26
27            // Display chapter information
28            println!("\n=== Chapters ({}) ===", epub.get_chapter_count());
29            for (i, chapter) in epub.get_chapters().iter().enumerate() {
30                println!(
31                    "Chapter {}: {} ({} file{})",
32                    i + 1,
33                    chapter.get_title(),
34                    chapter.get_file_count(),
35                    if chapter.get_file_count() == 1 {
36                        ""
37                    } else {
38                        "s"
39                    }
40                );
41
42                // Display files in each chapter
43                for (j, file) in chapter.get_files().iter().enumerate() {
44                    println!(
45                        "  File {}: {} ({})",
46                        j + 1,
47                        file.get_title().unwrap_or("No title"),
48                        file.get_href()
49                    );
50
51                    // Show if it's an HTML file
52                    if file.is_html() {
53                        println!("    [HTML file - {} bytes]", file.get_html_bytes().len());
54                    }
55                }
56            }
57
58            // Display table of contents
59            let toc = epub.get_table_of_contents();
60            println!(
61                "\n=== Table of Contents ({} entries) ===",
62                toc.get_entry_count()
63            );
64            for (i, entry) in toc.get_entries().iter().enumerate() {
65                let indent = "  ".repeat(entry.get_level() as usize);
66                println!(
67                    "{}{}: {} ({})",
68                    indent,
69                    i + 1,
70                    entry.get_title(),
71                    entry.get_href()
72                );
73            }
74
75            // Display total file count
76            println!("\n=== File Summary ===");
77            println!("Total files: {}", epub.get_file_count());
78            println!("All files:");
79            for (i, file) in epub.get_all_files().iter().enumerate() {
80                println!(
81                    "  {}: {} ({}) - {}",
82                    i + 1,
83                    file.get_title().unwrap_or("No title"),
84                    file.get_href(),
85                    file.get_media_type()
86                );
87            }
88        }
89        Err(e) => {
90            eprintln!("Error parsing EPUB: {}", e);
91            eprintln!("Make sure the file exists and is a valid EPUB file.");
92        }
93    }
94}
Source

pub fn get_entry_count(&self) -> usize

Examples found in repository?
examples/basic_usage.rs (line 62)
3fn main() {
4    // Example of how to use the epubie-lib library
5    let epub_path = "./example-files/iia.epub";
6
7    println!("Attempting to parse EPUB: {}", epub_path);
8
9    match Epub::new(epub_path.to_string()) {
10        Ok(epub) => {
11            // Display basic metadata
12            println!("\n=== EPUB Metadata ===");
13            println!("Title: {}", epub.get_title());
14            println!("Creator: {}", epub.get_creator());
15            println!("Language: {}", epub.get_language());
16            println!("Identifier: {}", epub.get_identifier());
17            println!("Date: {}", epub.get_date());
18
19            if let Some(publisher) = epub.get_publisher() {
20                println!("Publisher: {}", publisher);
21            }
22
23            if let Some(description) = epub.get_description() {
24                println!("Description: {}", description);
25            }
26
27            // Display chapter information
28            println!("\n=== Chapters ({}) ===", epub.get_chapter_count());
29            for (i, chapter) in epub.get_chapters().iter().enumerate() {
30                println!(
31                    "Chapter {}: {} ({} file{})",
32                    i + 1,
33                    chapter.get_title(),
34                    chapter.get_file_count(),
35                    if chapter.get_file_count() == 1 {
36                        ""
37                    } else {
38                        "s"
39                    }
40                );
41
42                // Display files in each chapter
43                for (j, file) in chapter.get_files().iter().enumerate() {
44                    println!(
45                        "  File {}: {} ({})",
46                        j + 1,
47                        file.get_title().unwrap_or("No title"),
48                        file.get_href()
49                    );
50
51                    // Show if it's an HTML file
52                    if file.is_html() {
53                        println!("    [HTML file - {} bytes]", file.get_html_bytes().len());
54                    }
55                }
56            }
57
58            // Display table of contents
59            let toc = epub.get_table_of_contents();
60            println!(
61                "\n=== Table of Contents ({} entries) ===",
62                toc.get_entry_count()
63            );
64            for (i, entry) in toc.get_entries().iter().enumerate() {
65                let indent = "  ".repeat(entry.get_level() as usize);
66                println!(
67                    "{}{}: {} ({})",
68                    indent,
69                    i + 1,
70                    entry.get_title(),
71                    entry.get_href()
72                );
73            }
74
75            // Display total file count
76            println!("\n=== File Summary ===");
77            println!("Total files: {}", epub.get_file_count());
78            println!("All files:");
79            for (i, file) in epub.get_all_files().iter().enumerate() {
80                println!(
81                    "  {}: {} ({}) - {}",
82                    i + 1,
83                    file.get_title().unwrap_or("No title"),
84                    file.get_href(),
85                    file.get_media_type()
86                );
87            }
88        }
89        Err(e) => {
90            eprintln!("Error parsing EPUB: {}", e);
91            eprintln!("Make sure the file exists and is a valid EPUB file.");
92        }
93    }
94}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.