Const equivalents of many bytemuck functions,
and additional functionality.
constmuck uses bytemuck's traits,
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.
This crate avoids requiring (unstable as of 2021) trait bounds in const fns
by using marker types to require that a trait is implemented.
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 IsTW;
;
Additional checks
Additional checks are enabled in debug builds,
all of which cause panics when it'd have otherwise been Undefined Behavior
(caused by unsound unsafe impls or calling unsafe constructor functions),
which means that there is a bug in some unsafe code somewhere.
The precise checks are left unspecified so that they can change at any time.
These checks are disabled by default in release builds, to enable them you can use this in your Cargo.toml:
[]
= true
Features
These are the features of this crate:
-
"derive"(disabled by default): Enablesbytemuck's"derive"feature and reexports its derives. -
"rust_latest_stable"(disabled by default): Enables all items and functionality that requires stable Rust versions after 1.56.0. Currently doesn't enable any other feature. -
"rust_1_57"(disabled by default, requires Rust 1.57.0): Causes this crate to use theconst_panicdependency, to improve the quality of panic messages.
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.
You can use the "rust_latest_stable" crate feature to get
all items and functionality that requires stable Rust versions after 1.56.0.
Plans
1.1.0: Add mutable equivalents of reference/slice methods.
This will require adding an opt-in feature.