pub struct BbfBuilder { /* private fields */ }Expand description
a BBF file builder
provides methods for making a bound book format (BBF) file with assets, pages, sections, and metadata. this builder handles deduplication of assets, string pooling, alignment, and integrity hashing.
Implementations§
Source§impl BbfBuilder
impl BbfBuilder
Sourcepub fn new<P: AsRef<Path>>(
output_path: P,
alignment: u8,
ream_size: u8,
flags: u32,
) -> Result<Self>
pub fn new<P: AsRef<Path>>( output_path: P, alignment: u8, ream_size: u8, flags: u32, ) -> Result<Self>
makes a new BBF builder with custom alignment and ream size
initializes a new BBF file at the specified path and writes the header. validates that alignment and ream size exponents are within acceptable bounds. prompts user for confirmation if alignment exponent exceeds 16 to prevent excessive fragmentation.
§Arguments
output_path- path where the BBF file will be madealignment- alignment exp for asset data (actual alignment = 1 << alignment bytes)ream_size- ream size exp for small asset threshold (actual size = 1 << ream_size bytes)flags- header flags for config opts
§Returns
a new BbfBuilder instance ready to accept assets, pages, sections, and metadata
§Errors
returns an error if:
- user declines the confirmation prompt for alignment > 16
- alignment exponent exceeds 16 (64kb) without user confirmation
- ream size exponent exceeds 16 (64kb)
- file creation fails
- writing the initial header fails
Sourcepub fn with_defaults<P: AsRef<Path>>(output_path: P) -> Result<Self>
pub fn with_defaults<P: AsRef<Path>>(output_path: P) -> Result<Self>
creates a new BBF builder with default settings
initializes a builder with standard alignment (12, or 4kb) and ream size (16, or 64kb), and enables variable ream size flag for optimizing small assets
§Arguments
output_path- path where the BBF file will be created
§Returns
a new BbfBuilder instance configured with default values
§Errors
returns an error if:
- file creation fails
- writing the initial header fails
Sourcepub fn calculate_hash_128(data: &[u8]) -> u128
pub fn calculate_hash_128(data: &[u8]) -> u128
Sourcepub fn calculate_hash_64(data: &[u8]) -> u64
pub fn calculate_hash_64(data: &[u8]) -> u64
Sourcepub fn add_page<P: AsRef<Path>>(
&mut self,
image_path: P,
page_flags: u32,
asset_flags: u32,
) -> Result<()>
pub fn add_page<P: AsRef<Path>>( &mut self, image_path: P, page_flags: u32, asset_flags: u32, ) -> Result<()>
adds a page (image) to the book
reads the image file, calculates its hash, and either reuses an existing asset (deduplication) or adds a new asset entry. applies appropriate alignment based on file size and configuration. creates a page entry that references the asset.
§Arguments
image_path- path to the image file to addpage_flags- flags for page-specific configurationasset_flags- flags for asset-specific configuration
§Returns
unit type on success, indicating the page was added
§Errors
returns an error if:
- reading the image file fails
- arithmetic operations overflow (protected by macroni_n_cheese::mathinator2000)
- writing image data to the buffer fails
- aligning padding fails
Sourcepub fn add_section(
&mut self,
title: &str,
start_index: u64,
parent: Option<&str>,
)
pub fn add_section( &mut self, title: &str, start_index: u64, parent: Option<&str>, )
adds a section (chapter/part) to the book
creates a section entry with a title, starting page index, and optional parent section. sections organize pages into hierarchical structures like chapters and sub-chapters.
§Arguments
title- the section title (stored in string pool)start_index- the first page index in this sectionparent- optional parent section title for hierarchical organization
§Returns
unit type on success (sections are stored internally)
Sourcepub fn add_metadata(&mut self, key: &str, val: &str, parent: Option<&str>)
pub fn add_metadata(&mut self, key: &str, val: &str, parent: Option<&str>)
adds a metadata key-val pair to the book
stores arbitrary metadata like author, title, publisher, or isbn. metadata can optionally be associated with a parent section.
§Arguments
key- the metadata key (stored in string pool)val- the metadata val (stored in string pool)parent- optional parent section for section-specific metadata
§Returns
unit type on success (metadata is stored internally)
Sourcepub fn finalize(self) -> Result<()>
pub fn finalize(self) -> Result<()>
finalizes the book file and writes all indices
writes all asset, page, section, and metadata tables to the file, followed by the string pool. calculates an integrity hash over all index data, writes the footer with all offsets and counts, then seeks back to the beginning to update the header with final values. flushes and syncs all data to disk.
§Returns
unit type on success, indicating the BBF file is complete and ready for use
§Errors
returns an error if:
- writing any table data fails
- arithmetic operations overflow (protected by macroni_n_cheese::mathinator2000)
- writing the footer fails
- flushing the buffer fails
- syncing to disk fails
- extracting the inner file from bufwriter fails
- seeking to the start of the file fails
- writing the updated header fails
Sourcepub const fn asset_count(&self) -> usize
pub const fn asset_count(&self) -> usize
Sourcepub const fn page_count(&self) -> usize
pub const fn page_count(&self) -> usize
Sourcepub const fn section_count(&self) -> usize
pub const fn section_count(&self) -> usize
Sourcepub const fn metadata_count(&self) -> usize
pub const fn metadata_count(&self) -> usize
Auto Trait Implementations§
impl Freeze for BbfBuilder
impl RefUnwindSafe for BbfBuilder
impl Send for BbfBuilder
impl Sync for BbfBuilder
impl Unpin for BbfBuilder
impl UnsafeUnpin for BbfBuilder
impl UnwindSafe for BbfBuilder
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more