bytes_to_type 0.1.1

A Rust library to facilitate byte conversion to specified types using macro generation.
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 16.19 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.09 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ri-nat/bytes_to_type
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ri-nat

bytes_to_type

Crates.io Documentation

A Rust library for converting slices of bytes to vectors of a specific type.

About

bytes_to_type allows you to conveniently convert slices of byte data into vectors of a specific type, handling necessary conversions and memory alignment seamlessly.

Key Features

  • Type Conversion: Easily convert slices of bytes into vectors of a specified type.
  • Memory Safety: Ensures that conversions maintain Rust’s guarantees of memory safety.

Getting Started

Installation

Add bytes_to_type to your Cargo.toml file:

[dependencies]
bytes_to_type = "0.1.1"

Example

use bytes_to_type::bytes_to_type;

// This macro will generate a function with the following signature:
// pub fn bytes_to_u32(bytes: &[u8]) -> Result<Vec<u32>, anyhow::Error>
bytes_to_type!(u32);

fn main() {
    let bytes = vec![1, 2, 3, 4, 5, 6, 7, 8];
    let result = bytes_to_u32(&bytes).expect("Failed to convert bytes to u32");

    assert_eq!(result, vec![67305985, 134678021]);    
}

License

This project is licensed under the MIT License.