commit | aed9482b38fd582aee0c711082f0c31b21af3eed | [log] [tgz] |
---|---|---|
author | Andrew Walbran <qwandor@google.com> | Thu Nov 09 13:52:13 2023 +0000 |
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | Thu Nov 09 13:52:13 2023 +0000 |
tree | 4209f66f61ffef543aa6398aef4b389b4ef7add0 | |
parent | 45c1a558bbb8dccd89b36600faa6240b1825706f [diff] | |
parent | 0d92849c5b88cf0679ea1c3380584a55398c56d4 [diff] |
Migrate to cargo_embargo. am: 5fb1732fb9 am: 927e6839f2 am: 0d92849c5b Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/bytemuck/+/2822245 Change-Id: If134c1ca04f44c684b2628b6ea0a3aea7b397d8d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
A crate for mucking around with piles of bytes.
This crate lets you safely perform “bit cast” operations between data types. That's where you take a value and just reinterpret the bits as being some other type of value, without changing the bits.
as
keywordFrom
traitf32::to_bits
, just generalized to let you convert between all sorts of data types.When a slice is involved it‘s not a direct bitcast. Instead, the cast_slice
and cast_slice_mut
functions will pull apart a slice’s data and give you a new slice that‘s the same span of memory just viewed as the new type. If the size of the slice’s element changes then the length of the slice you get back will be changed accordingly.
This lets you cast a slice of color values into a slice of u8
and send it to the GPU, or things like that. I‘m sure there’s other examples, but honestly this crate is as popular as it is mostly because of Rust's 3D graphics community wanting to cast slices of different types into byte slices for sending to the GPU. Hi friends! Push those vertices, or whatever it is that you all do.
While bytemuck
is full of unsafe code, I've also started a “sibling crate” called bitfrob, which is where operations that are 100% safe will be added.
bytemuck
in bigger projects.bytemuck
crate will continue to work with rustc-1.34
for at least the rest of the 1.y.z
versions.Future Plans: Once the Safe Transmute Project completes and stabilizes (“eventually”) this crate will be updated to use that as the underlying mechanism for transmutation bounds, and a 2.0 version of bytemuck
will be released. The hope is for the 1.0 to 2.0 transition to be as seamless as possible, but the future is always uncertain.