pub struct Book {
pub items: Vec<BookItem>,
}Expand description
A tree structure representing a book.
A book is just a collection of BookItems which are accessible by
either iterating (immutably) over the book with iter(), or recursively
applying a closure to each item to mutate the chapters, using
for_each_mut().
Fields§
§items: Vec<BookItem>The items in this book.
Implementations§
Source§impl Book
impl Book
Sourcepub fn new_with_items(items: Vec<BookItem>) -> Book
pub fn new_with_items(items: Vec<BookItem>) -> Book
Creates a new book with the given items.
Sourcepub fn chapters(&self) -> impl Iterator<Item = &Chapter>
pub fn chapters(&self) -> impl Iterator<Item = &Chapter>
A depth-first iterator over each Chapter, skipping draft chapters.
Sourcepub fn for_each_mut<F>(&mut self, func: F)
pub fn for_each_mut<F>(&mut self, func: F)
Recursively apply a closure to each item in the book, allowing you to mutate them.
§Note
Unlike the iter() method, this requires a closure instead of returning
an iterator. This is because using iterators can possibly allow you
to have iterator invalidation errors.
Sourcepub fn for_each_chapter_mut<F>(&mut self, func: F)
pub fn for_each_chapter_mut<F>(&mut self, func: F)
Recursively apply a closure to each non-draft chapter in the book, allowing you to mutate them.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Book
impl<'de> Deserialize<'de> for Book
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Book, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Book, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Book
impl Serialize for Book
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for Book
Auto Trait Implementations§
impl Freeze for Book
impl RefUnwindSafe for Book
impl Send for Book
impl Sync for Book
impl Unpin for Book
impl UnwindSafe for Book
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more