Skip to content

Commit 95d4f58

Browse files
committed
Document features and build targets, improve safety documentation
- Add comprehensive Features section to README explaining all feature flags - Document no_std and WASM build instructions with examples - Add safety invariant documentation to DataRegion struct - Address PR review feedback for improved documentation clarity
1 parent 085b17c commit 95d4f58

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,51 @@ the local system. Specifying the `DESTDIR` environment variable will allow you t
4949
DESTDIR=/my/custom/path make install
5050
```
5151

52+
## Features
53+
54+
The library supports various feature flags for different environments:
55+
56+
* `std` (default) - Standard library support, includes `alloc`
57+
* `alloc` - Heap allocation support (enables `Digest` trait, custom CRC params, checksum combining)
58+
* `cache` - Caches generated constants for custom CRC parameters (requires `alloc`)
59+
* `cli` - Enables command-line tools (`checksum`, `arch-check`, `get-custom-params`)
60+
* `ffi` - C/C++ FFI bindings for shared library
61+
* `panic-handler` - Provides panic handler for `no_std` environments (disable when building binaries)
62+
63+
### Building for no_std
64+
65+
For embedded targets without standard library:
66+
67+
```bash
68+
# Minimal no_std (core CRC only, no heap)
69+
cargo build --target thumbv7em-none-eabihf --no-default-features --lib
70+
71+
# With heap allocation (enables Digest, custom params)
72+
cargo build --target thumbv7em-none-eabihf --no-default-features --features alloc --lib
73+
74+
# With caching (requires alloc)
75+
cargo build --target thumbv7em-none-eabihf --no-default-features --features cache --lib
76+
```
77+
78+
Tested on ARM Cortex-M (`thumbv7em-none-eabihf`, `thumbv8m.main-none-eabihf`) and RISC-V (`riscv32imac-unknown-none-elf`).
79+
80+
### Building for WASM
81+
82+
For WebAssembly targets:
83+
84+
```bash
85+
# Minimal WASM
86+
cargo build --target wasm32-unknown-unknown --no-default-features --lib
87+
88+
# With heap allocation (typical use case)
89+
cargo build --target wasm32-unknown-unknown --no-default-features --features alloc --lib
90+
91+
# Using wasm-pack for browser
92+
wasm-pack build --target web --no-default-features --features alloc
93+
```
94+
95+
Tested on `wasm32-unknown-unknown`, `wasm32-wasip1`, and `wasm32-wasip2` targets.
96+
5297
## Usage
5398

5499
Add `crc-fast = version = "1.5"` to your `Cargo.toml` dependencies, which will enable every available optimization for

src/algorithm.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,13 @@ where
482482
}
483483

484484
/// Data region descriptor for overlapping SIMD reads in CRC processing
485+
///
486+
/// # Safety Invariants
487+
///
488+
/// When this struct is used with overlapping SIMD reads:
489+
/// - `offset` must be >= `CRC_CHUNK_SIZE` (16 bytes)
490+
/// - `remaining` must be in range 1..=15
491+
/// - `full_data` must contain at least `offset + remaining` bytes
485492
struct DataRegion<'a> {
486493
full_data: &'a [u8],
487494
offset: usize,

0 commit comments

Comments
 (0)