macro_rules! u16_tuple {
    ($NAME:ident, $ENDIAN:literal, $($DERIVE:ty),*) => { ... };
}
Expand description

Generates a tuple struct with a given name for managing a Numeric type u16 allocated on stack.

Arguments

  • NAME - name of the struct to be generated
  • ENDIAN - endianess of the numeric type, must be either le, be, or ne, this will be passed directly to the byteserde attribute as #[byteserde(endian = “xx” )]
  • [derive, ...]must include one of the following ByteSerializeStack, ByteSerializeHeap, or ByteDeserializeSlice other wise the #[byteserde(endian = $ENDIAN)] attribute will fail to compile. Plus list of additional valid rust derive traits

Derives

Note that provided implementation already includes several traits which SHOULD NOT be included in the derive list.

  • Display - provides a human readable sting view of the u16 value

From

Note that provided implementation already includes the following From implementations.

  • From<u16> - will take the u16 and return tupe struct with type of NAME agrument.
  • From<Name> - will take the struct type from the NAME argument and return the u16 value.

Examples

u16_tuple!(Number, "be", byteserde_derive::ByteSerializeStack, PartialEq, Debug);
 
let inp_num: Number = 1_u16.into(); // from u16
println!("inp_num: {:?}, {}", inp_num, inp_num);
assert_eq!(inp_num.value(), 1_u16);

let inp_num: Number = Number::new(2); // using new
println!("inp_num: {:?}, {}", inp_num, inp_num);
assert_eq!(inp_num.value(), 2_u16);
 
let inp_num: u16 = inp_num.into(); // to u16
assert_eq!(inp_num, 2_u16);