#[non_exhaustive]pub enum Value {
String(String),
Double(f64),
Bytes(Vec<u8>),
U16(u16),
U32(u32),
Map(BTreeMap<String, Value>),
I32(i32),
U64(u64),
U128(u128),
Array(Vec<Value>),
Bool(bool),
Float(f32),
}Expand description
One MMDB data-section value.
The variants correspond one-to-one with the data types defined by the MMDB format. There is deliberately no null/unit variant — MMDB has no null type; absence is modeled by omitting a map entry.
§Equality and hashing
Floating-point variants (Value::Float, Value::Double) compare and hash by their
raw bit pattern, so bit-identical values (including matching NaN payloads) are treated
as equal. This is what lets the writer deduplicate repeated values in the data section.
§Construction
use mmdb_writer::Value;
let scalar = Value::from(42_u32);
let list = Value::array([Value::from("a"), Value::from("b")]);
let map = Value::map([
("count", Value::from(2_u32)),
("items", list),
]);
assert!(matches!(map, Value::Map(_)));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
String(String)
UTF-8 string (type 2).
Double(f64)
IEEE 754 binary64 (type 3).
Bytes(Vec<u8>)
Arbitrary byte blob (type 4).
U16(u16)
Unsigned 16-bit integer (type 5).
U32(u32)
Unsigned 32-bit integer (type 6).
Map(BTreeMap<String, Value>)
String-keyed map (type 7). Backed by a BTreeMap so the encoded byte order — and
therefore the output — is deterministic.
I32(i32)
Signed 32-bit integer (extended type 8).
U64(u64)
Unsigned 64-bit integer (extended type 9).
U128(u128)
Unsigned 128-bit integer (extended type 10).
Array(Vec<Value>)
Ordered array (extended type 11).
Bool(bool)
Boolean (extended type 14).
Float(f32)
IEEE 754 binary32 (extended type 15).
Implementations§
Source§impl Value
impl Value
Sourcepub fn map<K, V, I>(entries: I) -> Self
pub fn map<K, V, I>(entries: I) -> Self
Build a Value::Map from key/value pairs.
Keys convert via Into<String> and values via Into<Value>, so string literals
and scalars can be passed directly.
use mmdb_writer::Value;
let v = Value::map([
("asn", Value::from(64_512_u32)),
("org", Value::from("Example, Inc.")),
]);Sourcepub fn array<V, I>(items: I) -> Self
pub fn array<V, I>(items: I) -> Self
Build a Value::Array from a sequence of values.
Elements convert via Into<Value>.
use mmdb_writer::Value;
let v = Value::array([Value::from(1_u32), Value::from(2_u32)]);Sourcepub fn merge_top_level(existing: &Value, new: &Value) -> Value
pub fn merge_top_level(existing: &Value, new: &Value) -> Value
Merge new onto existing, combining only the top level of two maps.
If both are Value::Map, the result contains every key from both; on a key present
in both, new’s value wins (no recursion into nested maps). If either side is not a
map, new is returned unchanged. This is the equivalent of the Go writer’s
TopLevelMergeWith inserter.
Sourcepub fn merge_deep(existing: &Value, new: &Value) -> Value
pub fn merge_deep(existing: &Value, new: &Value) -> Value
Merge new onto existing, recursing into nested maps and concatenating arrays.
- Two maps merge key by key, recursing on keys present in both.
- Two arrays concatenate (
existingelements followed bynewelements). - Any other combination yields
new.
This is the equivalent of the Go writer’s DeepMergeWith inserter.