{"repo":"Lokathor/bytemuck","free":true,"listed":false,"github":"https://github.com/Lokathor/bytemuck","clone":"git clone https://github.com/Lokathor/bytemuck.git","description":"A crate for mucking around with piles of bytes","language":"Rust","stars":1042,"topics":["rust","zlib-license"],"license":"Apache-2.0","category":"dev-tools","readme_excerpt":"Latest Docs.rs Here bytemuck 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. This is not like the [ as keyword][keyword-as] This is not like the [ From trait][from-trait] It is most like [ f32::to bits ][f32-to bits], just generalized to let you convert between all sorts of data types. [keyword-as]: https://doc.rust-lang.org/nightly/std/keyword.as.html [from-trait]: https://doc.rust-lang.org/nightly/core/convert/trait.From.html [f32-to bits]: https://doc.rust-lang.org/nightly/std/primitive.f32.html#method.to bits Here's the part you're more likely to care about: you can do this with slices too! 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","default_branch":null,"files":null,"tree":[],"storefront":"/r/Lokathor","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/Lokathor/bytemuck/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}