macro_rules! const_char_ascii {
($NAME:ident, $CONST:literal, true, $(#[$STRUCT_META:meta]),*) => { ... };
($NAME:ident, $CONST:literal, $(#[$STRUCT_META:meta]),*) => { ... };
}Expand description
Generates a tuple struct with a given name and a private ascii char allocated on stack using u8 whose
value always set to parameter CONST.
§Arguments
NAME- name of the struct to be generatedCONST-u8byte value to be used as the value behind this structtrue- Optional boolean flag to indicate if serde json should be derived or not interpreting buffer as a lossy utf-8 string#[derive(...)]– list of traits to derive for the struct
§Derives
Note that provided implementation already includes several traits which SHOULD NOT be included in the derive list.
- std::fmt::Debug & std::fmt::Display - provides a human readable sting view of the
u8byte as utf-8 char - byteserde::prelude::ByteDeserializeSlice- provides an implementation for deserializing from a byte stream, which returns byteserde::prelude::SerDesError if value on the
stream does
notmatch theCONSTvalue.
§Examples
use byteserde::prelude::*;
const_char_ascii!(One, b'1', #[derive(PartialEq)]);
let inp_const = One::default();
println!("inp_const: {:?}, {}", inp_const, inp_const);
assert_eq!(inp_const.value(), b'1');