pub enum ValueRef<'a> {
Utf8(&'a str),
Bytes(&'a [u8]),
Double(f64),
Float(f32),
Uint16(u16),
Uint32(u32),
Int32(i32),
Uint64(u64),
Uint128(u128),
Bool(bool),
Array(Vec<ValueRef<'a>>),
Map(Vec<(&'a str, ValueRef<'a>)>),
}Expand description
Borrowed representation of a decoded MMDB value.
String and byte payloads point directly into the source MMDB buffer. Arrays and maps allocate only their small container vectors; their scalar payloads remain borrowed.
Variants§
Utf8(&'a str)
Borrowed UTF-8 string.
Bytes(&'a [u8])
Borrowed byte string.
Double(f64)
IEEE-754 64-bit floating-point value.
Float(f32)
IEEE-754 32-bit floating-point value.
Uint16(u16)
Unsigned 16-bit integer.
Uint32(u32)
Unsigned 32-bit integer.
Int32(i32)
Signed 32-bit integer.
Uint64(u64)
Unsigned 64-bit integer.
Uint128(u128)
Unsigned 128-bit integer.
Bool(bool)
Boolean value.
Array(Vec<ValueRef<'a>>)
Ordered MMDB array whose elements may borrow the source buffer.
Map(Vec<(&'a str, ValueRef<'a>)>)
MMDB map represented as borrowed keys and borrowed/inline values.
Implementations§
Source§impl<'a> ValueRef<'a>
impl<'a> ValueRef<'a>
Sourcepub fn get(&self, key: &str) -> Option<&ValueRef<'a>>
pub fn get(&self, key: &str) -> Option<&ValueRef<'a>>
Gets a map field without allocating. Returns None for missing keys or
non-map values.
§Examples
use libmaxminddb_rs::ValueRef;
let value = ValueRef::Map(vec![("asn", ValueRef::Uint32(64512))]);
assert_eq!(value.get("asn"), Some(&ValueRef::Uint32(64512)));
assert_eq!(value.get("missing"), None);Sourcepub fn to_owned_value(&self) -> Value
pub fn to_owned_value(&self) -> Value
Converts to an owned value. This copies strings, bytes, and container contents so the result can outlive the MMDB buffer.
§Examples
use libmaxminddb_rs::{Value, ValueRef};
let borrowed = ValueRef::Utf8("example");
assert_eq!(borrowed.to_owned_value(), Value::Utf8("example".into()));