Macro byteserde_types::u16_tuple
source · 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 generatedENDIAN- endianess of the numeric type, must be eitherle,be, orne, this will be passed directly to thebyteserdeattribute as #[byteserde(endian = “xx” )][derive, ...]–must include one ofthe followingByteSerializeStack,ByteSerializeHeap, orByteDeserializeSliceother 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 theu16value
From
Note that provided implementation already includes the following From implementations.
From<u16>- will take theu16and return tupe struct with type ofNAMEagrument.From<Name>- will take thestructtype from theNAMEargument and return theu16value.
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);