Crates.io | swapbytes |
lib.rs | swapbytes |
version | 0.2.1 |
source | src |
created_at | 2023-11-20 04:41:08.04801 |
updated_at | 2023-11-21 06:54:07.541386 |
description | Crate for swapping the endianess of structures |
homepage | |
repository | https://github.com/jacobtread/bytereorder |
max_upload_size | |
id | 1041711 |
size | 5,800 |
Rust library for swapping the endianess of a structure using a derive macro
Using swapbytes
with cargo
[dependencies]
swapbytes = "0.2"
or
cargo add swapbytes
use swapbytes::SwapBytes;
#[derive(SwapBytes)]
pub struct Test {
pub a: u32,
pub b: u32,
/// Skip this field
#[sb(skip)]
pub b: String,
}
let mut value: Test = Test { a: 1, b: 4 };
value.swap_bytes_mut();
/* Enum must implement Clone, Copy */
#[derive(SwapBytes, Clone, Copy)]
#[repr(u32)] /* Only number repr types are supported */
pub enum ReprEnum {
A = 1,
B = 2
}