#[non_exhaustive]pub enum MapRepr {
HashMap,
BTreeMap,
Custom(String),
}Expand description
The owned Rust collection a proto map<K, V> field maps to in generated
owned structs.
The default is HashMap (std::collections::HashMap, or
hashbrown::HashMap under no_std). BTreeMap selects
the buffa-provided alloc::collections::BTreeMap for deterministic iteration
order with no extra dependency or consumer code.
Custom substitutes any map that satisfies the
buffa::map_codec::MapStorage bound — for example a crate-local newtype
wrapping indexmap::IndexMap.
Unlike the repeated knob (which wraps the element type and needs a *
placeholder template), a map type is always path<K, V> with both
parameters positional and buffa-resolved, so a custom path is a plain type
path (e.g. "::my_crate::OrderedMap") with no placeholder.
Select a representation through buffa_build’s map_type /
map_type_custom builder methods. The wire format is identical regardless of
the collection; only the in-memory owned type changes.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
HashMap
::buffa::__private::HashMap<K, V> — the default. Generated output is
byte-identical to a build without the knob.
BTreeMap
::buffa::alloc::collections::BTreeMap<K, V> — buffa-provided, no extra
dependency, deterministic key order (so encoded bytes are stable across
runs). The key type must be Ord, which every proto map key type
(integers, bool, string) satisfies.
Custom(String)
A custom map named by a fully-qualified Rust type path (e.g.
"::my_crate::OrderedMap"). The named type must satisfy
buffa::map_codec::MapStorage and be a crate-local newtype (a foreign
map cannot implement the buffa-owned reflection / serde traits).
§Limitations
- The path is a plain type path applied as
path<K, V>— it must not include the<K, V>parameters or a*placeholder. A path that does not parse as a Rust type surfaces asCodeGenError::InvalidTypePathat generation (.compile()) time. - The newtype must implement
buffa::map_codec::MapStorageplus the derive /FromIterator/ReflectMap/ serde /arbitrarybounds listed on that trait’s docs (the canonical list). JSON andarbitrarynow work for every proto map key/value type regardless of the container. The buffa-providedBTreeMapalready satisfies every bound, so prefer it unless you need a specific foreign map.