Skip to main content

Crate mbook_converter

Crate mbook_converter 

Source
Expand description

Convert books between mbook and other formats.

One type does the work: Converter. It takes a source as any Read or as a byte slice, and gives an mbook file written to any Write, or a Book that can still be changed. The optional export feature writes an existing book in another format.

use mbook_converter::Converter;
use std::fs::File;
use std::io::BufWriter;

let source = File::open("book.fb2")?;
let sink = BufWriter::new(File::create("book.mbook")?);
let report = Converter::new().convert(source, sink)?;

println!("converted from {}", report.format);
for warning in &report.warnings {
    eprintln!("{warning}");
}

The design is described in the docs/src/mbook-converter folder of the repository.

§Features

Each import format has a feature enabled by default.

FeatureFormat
epubEPUB 2 and 3
fb2FictionBook 2, plain or inside a ZIP
pdfPDF
cbzComic book archive
docxWord documents
htmlOne HTML document
mdOne Markdown document
txtPlain text

A source in a format whose feature is disabled is still recognised and refused with Error::FormatDisabled.

The opt-in rayon feature encodes the pictures of a source on all cores at once instead of one after another. The book is the same.

The opt-in export feature enables writing all eight formats, including their picture codecs, and figure, which draws the diagrams and formulas of a book. It currently requires Rust 1.98 or later.

Re-exports§

pub use mbook;

Structs§

ConvertLimits
Bounds applied before memory is reserved for something a source declares.
ConvertOptions
How a source is converted. Start from ConvertOptions::default and change the fields that matter.
Converted
A converted book that can still be changed, and what its conversion reported.
Converter
Converts books between mbook and other formats.
PictureOptions
How pictures are encoded as AVIF. A value outside its range is brought into the range.
Report
What a conversion found out.
Warning
One thing a conversion could not keep.

Enums§

Error
Why a conversion failed.
Format
A supported book format.
WarningKind
What a conversion lost.

Type Aliases§

Result
The result type of this crate.