postcard_bindgen_core/code_gen/
mod.rs

1mod available_check;
2mod export_registry;
3mod field_accessor;
4mod function;
5mod import_registry;
6mod switch_case;
7mod utils;
8mod variable_path;
9
10pub mod js;
11pub mod python;
12
13use crate::type_info::NumberMeta;
14
15const U8_BYTES_CONST: &str = "U8_BYTES";
16const U16_BYTES_CONST: &str = "U16_BYTES";
17const U32_BYTES_CONST: &str = "U32_BYTES";
18const U64_BYTES_CONST: &str = "U64_BYTES";
19const U128_BYTES_CONST: &str = "U128_BYTES";
20
21impl NumberMeta {
22    pub(crate) fn as_byte_string(&self) -> &'static str {
23        let bytes = match self {
24            NumberMeta::Integer { bytes, .. } => bytes,
25            NumberMeta::FloatingPoint { bytes } => bytes,
26        };
27        match bytes {
28            1 => U8_BYTES_CONST,
29            2 => U16_BYTES_CONST,
30            4 => U32_BYTES_CONST,
31            8 => U64_BYTES_CONST,
32            16 => U128_BYTES_CONST,
33            _ => unreachable!(),
34        }
35    }
36}