transmute-bytes 0.1.1

Simple. Safe. From bytes without loss
Documentation
  • Coverage
  • 0%
    0 out of 8 items documented0 out of 0 items with examples
  • Size
  • Source code size: 5.84 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.65 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • uselessgoddess/transmute-bytes
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • uselessgoddess

Simple. Safe. From bytes without loss

Usage

use transmute_bytes::transmute_bytes;

fn main() {
    // Your byte data
    let bytes = [1_u8, 2, 3, 4, 5, 6, 7, 8, 0, 1];
    // You will receive:
    // - `Cow::Borrow(slice)` if data is aligned to `u64`
    //    and  length is a multiple of the length of u64
    //    ----------------------------------------------
    // - `Cow::Owned(vec)` if data is not aligned to `u64`
    //    or length is not a multiple of the length of u64
    let cow = transmute_bytes::<u64>(&bytes);

    // It depends on your endian
    let le = cow.as_ref() == [578437695752307201, 256];
    let be = cow.as_ref() == [72623859790382856, 281474976710656];
    assert!(le || be);
}