Expand description
Fast, SIMD-accelerated CRC32 (IEEE) checksum computation.
§Usage
§Simple usage
For simple use-cases, you can call the hash() convenience function to
directly compute the CRC32 checksum for a given byte slice:
let checksum = crc32::hash(b"foo bar baz");§Advanced usage
For use-cases that require more flexibility or performance, for example when
processing large amounts of data, you can create and manipulate a Hasher:
use crc32::Hasher;
let mut hasher = Hasher::new();
hasher.update(b"foo bar baz");
let checksum = hasher.finalize();§Performance
This crate contains multiple CRC32 implementations:
- A fast baseline implementation which processes up to 16 bytes per iteration
- An optimized implementation for modern
x86usingsseandpclmulqdqinstructions - An optimized implementation for
aarch64using thecrc32instructions
Calling the Hasher::new constructor at runtime will perform a feature
detection to select the most optimal implementation for the current CPU
feature set.
§Memory safety
Due to the use of SIMD intrinsics for the optimized implementations, this
crate contains some amount of unsafe code. The baseline implementation is
safe, and the specialized implementations are exercised by the crate’s
tests, which are only compiled when the std feature is enabled.
§Feature flags
§std (default: enabled)
The crate can be built without the Rust std library, which is useful for
low-level use-cases such as embedded where no operating system is available.
To build the crate in a no_std context, disable the default std feature.
Because runtime CPU feature detection requires OS support, the specialized
SIMD implementations are unavailable when the std feature is disabled.
§nightly (default: disabled)
Enables unstable features that are only available on the nightly channel.
Enabling it makes the optimized aarch64 implementation available.
Structs§
- Hasher
- Represents an in-progress CRC32 computation.
Functions§
- hash
- Computes the CRC32 hash of a byte slice.