GithubHelp home page GithubHelp logo

cyberflamego / bytemuck Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lokathor/bytemuck

0.0 2.0 0.0 256 KB

A crate for mucking around with piles of bytes

Home Page: https://docs.rs/bytemuck

License: Apache License 2.0

Rust 99.98% Batchfile 0.02%

bytemuck's Introduction

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 core of the bytemuck crate will continue to work with rustc-1.34 for at least the rest of the 1.y.z versions.
  • Opt-in features of the crate are not held to the same standard, and may work only on the latest Stable or 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.

bytemuck's People

Contributors

a1phyr avatar cad97 avatar chorman0773 avatar cryze avatar cyndis avatar danielhenrymantilla avatar daxpedda avatar decathorpe avatar djmcnab avatar freax13 avatar fu5ha avatar heroickatora avatar icewind1991 avatar ignatenkobrain avatar jstarry avatar kimundi avatar lokathor avatar lpghatguy avatar lu15w1r7h avatar mystise avatar nicholasbishop avatar notgull avatar simonsapin avatar smoothdeveloper avatar soveu avatar theedward162 avatar thomcc avatar wafflelapkin avatar yanchith avatar zakarumych avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.