TocElement

Struct TocElement 

Source
pub struct TocElement {
    pub level: i32,
    pub url: String,
    pub title: String,
    pub raw_title: Option<String>,
    pub children: Vec<TocElement>,
}
Expand description

An element of the Table of contents

§Example

use epub_builder::TocElement;
TocElement::new("chapter_1.xhtml", "Chapter 1")
    .child(TocElement::new("chapter_1.xhtml#1", "Chapter 1, section 1")
              .child(TocElement::new("chapter_1.xhtml#1-1", "Chapter 1, section 1, subsection 1")));

Fields§

§level: i32

The level. 0: part, 1: chapter, 2: section, …

§url: String

The link

§title: String

Title of this entry

§raw_title: Option<String>

Title of this entry without HTML tags (if None, defaults to the main one)

§children: Vec<TocElement>

Inner elements

Implementations§

Source§

impl TocElement

Source

pub fn new<S1: Into<String>, S2: Into<String>>(url: S1, title: S2) -> TocElement

Creates a new element of the toc

By default, the element’s level is 1 and it has no children.

Source

pub fn raw_title<S: Into<String>>(self, title: S) -> TocElement

Adds an alternate version of the title without HTML tags.

Useful only if you disable escaping of HTML fields.

Source

pub fn level(self, level: i32) -> Self

Sets the level of a TocElement

Source

pub fn child(self, child: TocElement) -> Self

Add a child to this element.

This adjust the level of the child to be the level of its parents, plus 1; this means that there is no point in manually setting the level to elements added with this method.

§Example
use epub_builder::TocElement;
let elem = TocElement::new("foo.xhtml", "Foo")
    .child(TocElement::new("bar.xhtml", "Bar")
         .level(42));

// `Bar`'s level wiss still be `2`.
Source

pub fn add(&mut self, element: TocElement)

Add element to self or to children, according to its level

This will adds element directly to self if its level is equal or less to the last children element; else it will insert it to the last child.

See the add method of `Toc.

Trait Implementations§

Source§

impl Clone for TocElement

Source§

fn clone(&self) -> TocElement

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TocElement

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.