| Crates.io | bytes_to_type |
| lib.rs | bytes_to_type |
| version | 0.1.1 |
| created_at | 2023-10-10 02:54:27.444467+00 |
| updated_at | 2023-10-10 06:34:47.1126+00 |
| description | A Rust library to facilitate byte conversion to specified types using macro generation. |
| homepage | |
| repository | https://github.com/ri-nat/bytes_to_type |
| max_upload_size | |
| id | 998689 |
| size | 16,105 |
A Rust library for converting slices of bytes to vectors of a specific type.
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.
Add bytes_to_type to your Cargo.toml file:
[dependencies]
bytes_to_type = "0.1.1"
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]);
}
This project is licensed under the MIT License.