const_char_ascii

Macro const_char_ascii 

Source
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 generated
  • CONST - u8 byte value to be used as the value behind this struct
  • true - 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.

§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');