Const equivalents of many bytemuck functions.
constmuck uses bytemuck's traits,
any type that implements those traits can be used with the
relevant functions from this crate.
Because the *_alt functions are const fns,
they can't inspect the address of the reference parameter.
This differs from their bytemuck equivalents,
which use the address to determine alignment.
Examples
These examples use bytemuck's derives to show how users don't need to
write unsafe to use this crate,
and use the konst crate to make writing the const functions easier.
Contiguous
This example demonstrates constructing an enum from its representation.
use Contiguous;
use ;
Wrapper
This example demonstrates a type that wraps a [T], constructed by reference.
use TransparentWrapper;
;
Additional checks
The "debug_checks" crate feature (which is disabled by default)
enables additional assertions in constmuck functions,
these assertions panic in some cases where unsound impls of bytemuck traits
would have caused Undefined Behavior.
Features
These are the features of this crate:
-
"derive"(disabled by default): Enablesbytemuck's"derive"feature and reexports its derives. -
"debug_checks"(disabled by default): Enables additional safety checks for detecting some Undefined Behavior. -
"rust_1_75"(disabled by default): allowsconstmuck::zeroedto construct types of any size. -
"rust_latest_stable"(disabled by default): enables all"rust_1_*"features.
No-std support
constmuck is #![no_std], it can be used anywhere Rust can be used.
Minimum Supported Rust Version
constmuck requires Rust 1.65.0.
You can use the "rust_latest_stable" crate feature to get
all items and functionality that requires stable Rust versions after 1.65.0.