Skip to main content

hadris_common/
lib.rs

1//! # Hadris Common
2//!
3//! Shared types and utilities used across the Hadris filesystem crates.
4//!
5//! This crate provides foundational types for working with on-disk filesystem
6//! structures, including endian-aware integers, extents, fixed-length filenames,
7//! path manipulation, and optical media constants.
8//!
9//! ## Feature Flags
10//!
11//! | Feature    | Default | Description |
12//! |------------|---------|-------------|
13//! | `std`      | yes     | Standard library support (CRC, chrono, rand) |
14//! | `alloc`    | via std | Heap allocation (`String`, `Vec` types) |
15//! | `bytemuck` | yes     | Zero-copy serialization for number types |
16//! | `optical`  | no      | Optical media types for CD/DVD/Blu-ray |
17//! | `sync`     | via std | Synchronous I/O (forwarded to `hadris-io`) |
18//! | `async`    | no      | Asynchronous I/O (forwarded to `hadris-io`) |
19//!
20//! ## Key Types
21//!
22//! - **Endian numbers**: [`types::number::U16`], [`types::number::U32`],
23//!   [`types::number::U64`] — unsigned integers parameterized by endianness.
24//! - **Extent**: [`types::extent::Extent`] — a contiguous region on disk
25//!   (sector + length).
26//! - **FixedFilename**: [`types::file::FixedFilename`] — a stack-allocated
27//!   filename with a compile-time maximum length.
28//! - **EndianType / Endianness**: [`types::endian::EndianType`],
29//!   [`types::endian::Endianness`] — runtime and compile-time endianness.
30//!
31//! ## Example
32//!
33//! ```rust
34//! use hadris_common::types::endian::{Endian, LittleEndian};
35//! use hadris_common::types::number::U32;
36//!
37//! let value = U32::<LittleEndian>::new(0x12345678);
38//! assert_eq!(value.get(), 0x12345678);
39//! ```
40
41#![no_std]
42
43#[cfg(feature = "alloc")]
44extern crate alloc;
45
46#[cfg(feature = "std")]
47extern crate std;
48
49/// Algorithms (requires std for CRC and random)
50#[cfg(feature = "std")]
51pub mod alg;
52/// Path utilities
53#[cfg(feature = "alloc")]
54pub mod path;
55/// Strings (requires alloc for String/Vec)
56#[cfg(feature = "alloc")]
57pub mod str;
58/// Types
59pub mod types;
60
61/// Optical media types (requires `optical` feature)
62#[cfg(feature = "optical")]
63pub mod optical;
64
65/// A generic 512-byte boot sector binary.
66///
67/// When written to the start of a disk image, this boot sector displays a
68/// message informing the user that the image is not directly bootable.
69///
70/// ```rust
71/// assert_eq!(hadris_common::BOOT_SECTOR_BIN.len(), 512);
72/// // Boot sector signature at end
73/// assert_eq!(hadris_common::BOOT_SECTOR_BIN[510], 0x55);
74/// assert_eq!(hadris_common::BOOT_SECTOR_BIN[511], 0xAA);
75/// ```
76pub static BOOT_SECTOR_BIN: &[u8] = include_bytes!("boot_sector.bin");
77
78#[cfg(test)]
79mod tests {
80    use super::*;
81
82    static_assertions::const_assert!(BOOT_SECTOR_BIN.len() == 512);
83}