• Stars
    star
    682
  • Rank 66,258 (Top 2 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A crate for mucking around with piles of bytes

License:Zlib Minimum Rust Version crates.io

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
  • This is not like the From trait
  • It is most like f32::to_bits, just generalized to let you convert between all sorts of data types.

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 is that you all do.

See Also

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.

Stability

  • The crate is 1.0 and I consider this it to be "basically done". New features are usually being accepted when other people want to put in the work, but myself I wanna move on to using bytemuck in bigger projects.
  • The default build of the bytemuck crate will continue to work with rustc-1.34 for at least the rest of the 1.y.z versions.
  • Any other cargo features of the crate are not held to the same standard, and may work only on the latest Stable or even only on latest Nightly.

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.

More Repositories

1

tinyvec

Just, really the littlest Vec you could need. So smol.
Rust
643
star
2

wide

A crate to help you go wide. By which I mean use SIMD stuff.
Rust
261
star
3

beryllium

An opinionated set of high level wrappers for the `fermium` SDL2 bindings.
Rust
64
star
4

fermium

An easy to build and use set of SDL2 bindings.
C
60
star
5

safe_arch

Exposes arch-specific intrinsics as safe function (via cfg).
Rust
46
star
6

bitfrob

Helps you frob those bits
Rust
32
star
7

phosphorus

gl.xml parser / GL bindings generator
Rust
17
star
8

gba-from-scratch

How to program for the GBA, from scratch
Rust
14
star
9

zstring

Zero-terminated string types for FFI.
Rust
13
star
10

rusty-xinput

Safe dynamic loading of xinput
Rust
12
star
11

gl33

Rust bindings to OpenGL 3.3
Rust
9
star
12

utf16_lit

Lets you make utf16 literals in rust.
Rust
9
star
13

chlorine

Just the C types for `no_std`, but builds faster.
Rust
8
star
14

pack1

Byte array newtypes of various primitive types.
Rust
8
star
15

randomize

Minimal randomization library.
Rust
5
star
16

magnesium

A minimal XML iterator.
Rust
5
star
17

gl46

Rust bindings to OpenGL 4.6 (plus some extensions)
Rust
5
star
18

vkvk

A vulkan library.
Rust
5
star
19

sdl3-sys-rs

Rust
4
star
20

yacurses

yet another curses lib
C
4
star
21

dice-bot-rs

A Discord bot for rolling dice
Rust
4
star
22

dmgrs

Dot-matrix Game: Rusty Style
Rust
4
star
23

gba-from-scratch-rs

GBA From Scratch With Rust
Rust
4
star
24

gamecrab

A Game Boy (Color) emulator project written in Rust.
Rust
4
star
25

sharecart1000-rs

A sharecart1000 library for rust
Rust
3
star
26

gba-img-convert

An image converter program for making GBA compatible data
Rust
3
star
27

png_filters

PNG filtering related functions
Rust
3
star
28

lawrencium

Bindings to a very limited subset of the Win32 API.
Rust
3
star
29

gba-compression

Pure Rust implementations of the compression/decompression routines used by the GBA
Rust
3
star
30

rpgsanta_2022

Lokathor's RPG Santa entry for 2022
Rust
3
star
31

bracer

Macros to help write ARM assembly
Rust
3
star
32

ptr_iter

Crate for iterating a pointer.
Rust
3
star
33

uwu

OwO
Rust
3
star
34

gles30

Rust bindings for GLES 3.0
Rust
3
star
35

imagine

Barebones image opening library.
Rust
3
star
36

hektor

Math library
Rust
3
star
37

chromium

Helps add some stability to your metal!
Rust
2
star
38

yagbas

Yet Another Game Boy Assembler
Rust
2
star
39

pixel_formats

Types for various pixel formats.
Rust
2
star
40

tagged_bytes

Rust
1
star
41

const_parse

Provides `const fn` for parsing values. Currently, only `u128` is supported.
Rust
1
star
42

kpasim

Yet another game boy emulator, the world will never have enough.
Rust
1
star
43

flerovium

Experiments with Gameboy stuff
Rust
1
star
44

aeabi_fns

Rust
1
star