Const equivalents of many bytemuck functions,
and a few additional const functions.
constmuck uses bytemuck's traits,
so any type that implements those traits can be used with the
relevant functions from this crate.
The *_alt functions aren't exactly equivalent to the bytemuck ones,
each one describes how it's different.
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 ;
use ;
Wrapper
This example demonstrates a type that wraps a [T], constructed by reference.
use TransparentWrapper;
use infer_tw;
;
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): Enablesadditional checks
Additional checks
The "debug_checks" feature enables additional checks,
all of which cause panics when it'd have otherwise been Undefined Behavior
(caused by unsound unsafe impls or calling unsafe constructor functions).
Size checks
Functions that transmute values check that the value doesn't change size when transmuted.
Functions that transmute references check that referent (the T in &T)
doesn't change size when transmuted.
Macros that transmute references check that reference doesn't change size when transmuted
(ie: transmuting &[u8] to &u8).
Macros have weaker checking than functions because they allow references to !Sized types
(eg: str, [u8], dyn Trait),
if you're only casting references to Sized types it's better to use the function equivalents.
Alignment checks
All the functions in the wrapper module check that the alignment of the
Inner type parameter is the same as the Outer type parameter,
in addition to the size checks described in the previous section.
Contiguous checks
The from_* functions in the contiguous module check that the
min_value of the passed-in ImplsContiguous is less than its max_value .
No-std support
constmuck is #![no_std], it can be used anywhere Rust can be used.
Minimum Supported Rust Version
constmuck requires Rust 1.56.0, because it uses transmute inside const fns.