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, layout helpers, and
7//! optical media constants. Reusable fixed-capacity storage and virtual paths
8//! live in `hadris-fixed` and `hadris-path` respectively.
9//!
10//! ## Feature Flags
11//!
12//! | Feature | Default | Description |
13//! |------------|---------|-------------|
14//! | `std` | yes | Standard library support (CRC, chrono, rand) |
15//! | `alloc` | via std | Heap allocation (`String`, `Vec` types) |
16//! | `bytemuck` | yes | Zero-copy serialization for number types |
17//! | `optical` | no | Optical media types for CD/DVD/Blu-ray |
18//! | `sync` | via std | Synchronous I/O (forwarded to `hadris-io`) |
19//! | `async` | no | Asynchronous I/O (forwarded to `hadris-io`) |
20//!
21//! ## Key Types
22//!
23//! - **Endian numbers**: [`types::number::U16`], [`types::number::U32`],
24//! [`types::number::U64`] — unsigned integers parameterized by endianness.
25//! - **Extent**: [`types::extent::Extent`] — a contiguous region on disk
26//! (sector + length).
27//! - **EndianType / Endianness**: [`types::endian::EndianType`],
28//! [`types::endian::Endianness`] — runtime and compile-time endianness.
29//!
30//! ## Example
31//!
32//! ```rust
33//! use hadris_common::types::endian::{Endian, LittleEndian};
34//! use hadris_common::types::number::U32;
35//!
36//! let value = U32::<LittleEndian>::new(0x12345678);
37//! assert_eq!(value.get(), 0x12345678);
38//! ```
39
40#![no_std]
41#![deny(missing_docs)]
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/// Types
53pub mod types;
54
55/// Optical media types (requires `optical` feature)
56#[cfg(feature = "optical")]
57pub mod optical;
58
59/// A generic 512-byte boot sector binary.
60///
61/// When written to the start of a disk image, this boot sector displays a
62/// message informing the user that the image is not directly bootable.
63///
64/// ```rust
65/// assert_eq!(hadris_common::BOOT_SECTOR_BIN.len(), 512);
66/// // Boot sector signature at end
67/// assert_eq!(hadris_common::BOOT_SECTOR_BIN[510], 0x55);
68/// assert_eq!(hadris_common::BOOT_SECTOR_BIN[511], 0xAA);
69/// ```
70pub static BOOT_SECTOR_BIN: &[u8] = include_bytes!("boot_sector.bin");
71
72#[cfg(test)]
73mod tests {
74 use super::*;
75
76 static_assertions::const_assert!(BOOT_SECTOR_BIN.len() == 512);
77}