Skip to main content

Value

Enum Value 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

pub fn map<K, V, I>(entries: I) -> Self
where K: Into<String>, V: Into<Value>, I: IntoIterator<Item = (K, V)>,

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.")),
]);
Source

pub fn array<V, I>(items: I) -> Self
where V: Into<Value>, I: IntoIterator<Item = V>,

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)]);
Source

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.

Source

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 (existing elements followed by new elements).
  • Any other combination yields new.

This is the equivalent of the Go writer’s DeepMergeWith inserter.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Value

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Value

Source§

impl From<&str> for Value

Source§

fn from(v: &str) -> Self

Converts to this type from the input type.
Source§

impl From<BTreeMap<String, Value>> for Value

Source§

fn from(v: BTreeMap<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(v: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(v: Vec<Value>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(v: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(v: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(v: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(v: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(v: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(v: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(v: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(v: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(v: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for Value

Source§

fn from(v: u128) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<(String, Value)> for Value

Source§

fn from_iter<I: IntoIterator<Item = (String, Value)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Value> for Value

Source§

fn from_iter<I: IntoIterator<Item = Value>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Value

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Value

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.