|new 1.10.0||Jul 3, 2022|
|1.9.0||Mar 30, 2022|
|1.7.3||Dec 16, 2021|
|1.7.2||Jul 23, 2021|
#38 in Encoding
631,433 downloads per month
Used in 2,695 crates (328 directly)
A crate for mucking around with piles of bytes.
The goal is to stay at 1.y.z until at least the next edition of Rust.
I consider any increase of the Minimum Rust Version to be a semver breaking change,
rustc-1.34 will continue to be supported for at least the rest of the
bytemuck-1.y.z series of the crate.
(The secret goal is to get all of this functionality into the standard library some day so that we don't even need to import a crate to do all this fun stuff.)
This crate gives small utilities for casting between plain data types.
Data comes in five basic forms in Rust, so we have five basic casting functions:
&mut Tuses [
&mut [T]uses [
Some casts will never fail (eg:
cast::<u32, f32> always works), other
casts might fail (eg:
cast_ref::<[u8; 4], u32> will fail if the reference
isn't already aligned to 4). Each casting function has a "try" version which
will return a
Result, and the "normal" version which will simply panic on
All the functions here are guarded by the [
Pod] trait, which is a
sub-trait of the [
If you're very sure that your type is eligible, you can implement those
traits for your type and then they'll have full casting support. However,
these traits are
unsafe, and you should carefully read the requirements
before adding the them to your own types.
- This crate is core only by default, but if you're using Rust 1.36 or later
you can enable the
extern_crate_alloccargo feature for some additional methods related to
Vec. Note that the
docs.rsdocumentation is always built with
extern_crate_alloccargo feature enabled.