#macro-derive #swapping #enums #field #repr #swapbytes #swap-bytes

macro swapbytes-derive

Derive macros for working with the swapbytes crate

2 unstable releases

0.2.0 Nov 21, 2023
0.1.1 Nov 20, 2023

#10 in #swapping

Download history 5/week @ 2024-02-16 15/week @ 2024-02-23 10/week @ 2024-03-01 10/week @ 2024-03-08 3/week @ 2024-03-15 11/week @ 2024-03-22 69/week @ 2024-03-29 3/week @ 2024-04-05 1/week @ 2024-04-19

76 downloads per month
Used in swapbytes

MIT license

5KB
66 lines

Swapbytes

License Cargo Version Cargo Downloads

Rust library for swapping the endianess of a structure using a derive macro

Cargo

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
}

Dependencies

~0.6–1.1MB
~25K SLoC