glossa_dsl/
resolver.rs

1#[cfg(feature = "bincode")]
2#[cfg(feature = "std")]
3mod bin_code;
4
5#[cfg(feature = "bincode")]
6pub(crate) mod bin_code_nostd;
7
8mod from_slice;
9mod lookup_value;
10mod ordered_map;
11
12#[cfg(feature = "std")]
13mod std_impl;
14
15use alloc::collections::BTreeMap;
16
17/// Compact string type optimized for small string storage.
18/// - Uses stack storage for strings <= 24 bytes (for 64-bit sys).
19/// - Fallback to heap allocation for longer strings.<hr>
20pub use compact_str::CompactString as MiniStr;
21//
22#[cfg(feature = "std")]
23pub use kstring::KString;
24
25use crate::template::Template;
26
27#[cfg(feature = "std")]
28pub type AHashRawMap = ahash::HashMap<KString, MiniStr>;
29
30pub type BTreeRawMap = BTreeMap<MiniStr, MiniStr>;
31
32#[cfg(feature = "std")]
33pub type AST = ahash::HashMap<KString, Template>;
34
35#[cfg(feature = "std")]
36pub type OrderedAST = BTreeMap<KString, Template>;
37
38#[cfg(not(feature = "std"))]
39pub type OrderedAST = BTreeMap<MiniStr, Template>;
40
41#[cfg(not(feature = "std"))]
42pub type AST = OrderedAST;
43
44/// Main template resolution engine
45///
46/// ## Implementation Notes
47///
48/// - `cfg(feature = "std")`
49///   - Uses HashMap with std for O(1) lookups
50/// - no_std:
51///   - Falls back to BTreeMap in no_std (O(log n) lookups)
52#[derive(Default, Debug, Clone, PartialEq)]
53#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
54pub struct Resolver(pub AST);
55
56impl core::ops::Deref for Resolver {
57  type Target = AST;
58
59  fn deref(&self) -> &Self::Target {
60    &self.0
61  }
62}