postcard_bindgen_core/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2
3extern crate alloc;
4
5#[cfg(feature = "generating")]
6pub mod code_gen;
7#[cfg(feature = "generating")]
8pub mod path;
9#[cfg(feature = "generating")]
10pub mod registry;
11#[cfg(feature = "generating")]
12pub mod type_info;
13
14#[cfg(feature = "generating")]
15pub use genco::lang;
16
17pub enum ArchPointerLen {
18    U32,
19    U64,
20}
21
22impl ArchPointerLen {
23    #[allow(unused)]
24    pub(crate) fn into_bytes(self) -> usize {
25        match self {
26            ArchPointerLen::U32 => 4,
27            ArchPointerLen::U64 => 8,
28        }
29    }
30}
31
32/// Helper struct to pass the generated language strings to an export function.
33#[cfg(feature = "generating")]
34#[derive(Debug)]
35pub struct Exports<L: genco::lang::Lang> {
36    pub files: Vec<ExportFile<L>>,
37}
38
39#[cfg(feature = "generating")]
40impl<L: genco::lang::Lang> Exports<L> {
41    pub fn file(&self, content_type: impl AsRef<str>) -> Option<&genco::Tokens<L>> {
42        self.files
43            .iter()
44            .find(|f| f.content_type.as_str() == content_type.as_ref())
45            .map(|f| &f.content)
46    }
47
48    pub fn pop_file(&mut self, content_type: impl AsRef<str>) -> Option<genco::Tokens<L>> {
49        let index = self
50            .files
51            .iter()
52            .position(|f| f.content_type.as_str() == content_type.as_ref())?;
53        Some(self.files.remove(index).content)
54    }
55}
56
57#[cfg(feature = "generating")]
58#[derive(Debug)]
59pub struct ExportFile<L: genco::lang::Lang> {
60    pub content_type: String,
61    pub content: genco::Tokens<L>,
62}