Crate theory

source ·
Expand description

This crate provides a library to store and load documentation content in a single file.

Content is organized into pages. The collection of pages is a book. Both pages and books can contain metadata entries.

Books

The main type in the crate is Book. A Book may contains multiple pages and metadata entries.

Creating a New Book

New books are created with BookBuilder.

Content is added with add_metadata and new_page.

When the book is completed, it can be persisted with dump.

Optionally, data can be compressed with set_compression.

Example

use theory::{MetadataEntry, Book, Page};
use std::io::{Cursor, Read, Write};

let mut buffer: Vec<u8> = Vec::new();

let mut builder = Book::builder();
builder.new_page("First").set_content("1");
builder.new_page("Second").set_content("2");

builder
    .add_metadata(MetadataEntry::Title("Theory Example".into()))
    .dump(Cursor::new(&mut buffer));

let book = Book::load(Cursor::new(buffer)).unwrap();

assert_eq!(book.num_pages(), 2);

Loading a Book

A book written by BookBuilder::dump can be loaded with Book::load.

Crate Features

Features can be used for controlling some functionalities in the library:

  • deflate

    Add supports for compressing books with DEFLATE.

  • lz4

    Add supports for compressing books with LZ4.

All features are enabled by default.

Modules

Types to describe errors.

Structs

A book loaded from an input stream, like a file.
A builder for new books.
A single page in a book.
Page identifier.
Entry in the TOC tree.

Enums

Method to compress data in blocks.
Metadata associated to a book or a page.