[][src]Struct epub_builder::Toc

pub struct Toc {
    pub elements: Vec<TocElement>,
}

A Table Of Contents

It basically contains a list of TocElements.

Example

Creates a Toc, fills it, and render it to HTML:

use epub_builder::{Toc, TocElement};
Toc::new()
   // add a level-1 element
   .add(TocElement::new("intro.xhtml", "Introduction"))
   // add a level-1 element with children
   .add(TocElement::new("chapter_1.xhtml", "Chapter 1")
           .child(TocElement::new("chapter_1.xhtml#section1", "1.1: Some section"))
           .child(TocElement::new("chapter_1.xhtml#section2", "1.2: another section")))
   // add a level-2 element, which will thus get "attached" to previous level-1 element
   .add(TocElement::new("chapter_1.xhtml#section3", "1.3: yet another section")
           .level(2))
   // render the toc (non-numbered list) and returns a string
   .render(false);

Fields

elements: Vec<TocElement>

The elements composing the TOC

Methods

impl Toc[src]

pub fn new() -> Toc[src]

Creates a new, empty, Toc

pub fn is_empty(&self) -> bool[src]

Returns true if the toc is empty, false else.

Note that empty here means that the the toc has zero or one element, since it's still not worth displaying it in this case.

pub fn add(&mut self, element: TocElement) -> &mut Self[src]

Adds a TocElement to the Toc.

This will look at the element's level and will insert it as a child of the last element of the Toc that has an inferior level.

Example

let mut toc = Toc::new();
// Insert an element at default level (1)
toc.add(TocElement::new("chapter_1.xhtml", "Chapter 1"));

// Insert an element at level 2
toc.add(TocElement::new("section_1.xhtml", "Section 1")
          .level(2));
// "Section 1" is now a child of "Chapter 1"

There are some cases where this behaviour might not be what you want; however, it makes sure that the TOC can still be renderer correctly for HTML and EPUB.

pub fn render_epub(&mut self) -> String[src]

Render the Toc in a toc.ncx compatible way, for EPUB.

pub fn render(&mut self, numbered: bool) -> String[src]

Render the Toc in either

    or
      form (according to numbered)

Trait Implementations

impl Default for Toc[src]

impl Debug for Toc[src]

Auto Trait Implementations

impl Unpin for Toc

impl Sync for Toc

impl Send for Toc

impl RefUnwindSafe for Toc

impl UnwindSafe for Toc

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]