Skip to main content

epub_stream/
lib.rs

1//! epub-stream -- Memory-efficient EPUB parser for embedded systems
2//!
3//! Streaming EPUB parser designed for constrained devices. Provides SAX-style
4//! XML parsing, XHTML tokenization, and optional text layout/pagination.
5//!
6//! # Features
7//!
8//! - `std` (default) -- enables streaming ZIP reader and file I/O
9//! - `layout` -- text layout engine for pagination
10//!
11//! # Allocation Behavior
12//!
13//! This crate uses an alloc-bounded design with explicit limits on all
14//! expensive entrypoints. The primary APIs require caller-provided buffers
15//! or scratch space (`*_with_scratch`, `*_into`). Convenience APIs that
16//! allocate (`read_resource() -> Vec<u8>`) are available only with the `std`
17//! feature and are clearly marked as non-embedded-fast-path.
18
19#![cfg_attr(not(feature = "std"), no_std)]
20#![warn(missing_docs)]
21#![cfg_attr(
22    not(test),
23    deny(
24        clippy::disallowed_methods,
25        clippy::expect_used,
26        clippy::unwrap_used,
27        clippy::panic,
28        clippy::panic_in_result_fn,
29        clippy::todo,
30        clippy::unimplemented
31    )
32)]
33#![deny(
34    clippy::large_enum_variant,
35    clippy::large_stack_arrays,
36    clippy::redundant_clone
37)]
38#![warn(
39    clippy::box_collection,
40    clippy::needless_collect,
41    clippy::map_clone,
42    clippy::implicit_clone,
43    clippy::inefficient_to_string
44)]
45extern crate alloc;
46
47pub mod css;
48pub mod error;
49pub mod metadata;
50pub mod navigation;
51pub mod spine;
52pub mod streaming;
53pub mod tokenizer;
54
55#[cfg(feature = "layout")]
56pub mod layout;
57
58#[cfg(feature = "std")]
59pub mod book;
60
61#[cfg(feature = "std")]
62pub mod validate;
63
64#[cfg(feature = "std")]
65pub mod render_prep;
66
67#[cfg(feature = "async")]
68pub mod async_api;
69
70#[cfg(feature = "std")]
71pub mod zip;
72
73// Re-export key types for convenience
74#[cfg(feature = "async")]
75pub use async_api::{open_epub_file_async, open_epub_file_async_with_options};
76#[cfg(feature = "std")]
77pub use book::{
78    parse_epub_file, parse_epub_file_with_options, parse_epub_reader,
79    parse_epub_reader_with_options, ChapterRef, ChapterStreamResult, CoverImageOptions,
80    CoverImageRef, CoverImageSource, EpubBook, EpubBookBuilder, EpubBookOptions, EpubSummary,
81    ImageReadOptions, Locator, PaginationSession, ReadingPosition, ReadingSession,
82    ResolvedLocation, ValidationMode,
83};
84pub use css::{CssStyle, Stylesheet};
85pub use error::{
86    EpubError, ErrorLimitContext, ErrorPhase, LimitKind, PhaseError, PhaseErrorContext, ZipError,
87    ZipErrorKind,
88};
89pub use metadata::EpubMetadata;
90pub use navigation::Navigation;
91#[cfg(feature = "std")]
92pub use render_prep::{
93    BlockRole, ChapterStylesheets, ComputedTextStyle, EmbeddedFontFace, EmbeddedFontStyle,
94    FontFallbackPolicy, FontLimits, FontPolicy, FontResolutionTrace, FontResolver, LayoutHints,
95    MemoryBudget, PreparedChapter, RenderPrep, RenderPrepError, RenderPrepOptions, RenderPrepTrace,
96    ResolvedFontFace, StyleConfig, StyleLimits, StyledChapter, StyledEvent, StyledEventOrRun,
97    StyledImage, StyledRun, Styler, StylesheetSource,
98};
99pub use spine::Spine;
100pub use streaming::{
101    ChunkAllocator, ChunkLimits, PaginationContext, ScratchBuffers, StreamingChapterProcessor,
102    StreamingStats,
103};
104pub use tokenizer::{
105    tokenize_html_into, tokenize_html_limited, tokenize_html_with_scratch, Token, TokenizeError,
106    TokenizeLimits, TokenizeScratch,
107};
108#[cfg(feature = "std")]
109pub use validate::{
110    validate_epub_file, validate_epub_file_with_options, validate_epub_reader,
111    validate_epub_reader_with_options, ValidationDiagnostic, ValidationOptions, ValidationReport,
112    ValidationSeverity,
113};
114#[cfg(feature = "std")]
115pub use zip::ZipLimits;