pub enum Value {
Show 20 variants
Null,
Bool(bool),
Int(i64),
Uint(u64),
Int128(i128),
Uint128(u128),
Float(f64),
String(String),
DateTime(String),
Date(String),
Time(String),
Ipv4(Ipv4Addr),
Ipv6(Ipv6Addr),
Inet(String),
Cidr(String),
MacAddr(String),
MacAddr8(String),
Uuid(String),
Array(Vec<Value>),
Object(BTreeMap<String, Value>),
}Expand description
Dynamic config value.
Variants§
Null
Bool(bool)
Int(i64)
Uint(u64)
Int128(i128)
128-bit signed — only from the table i128 type (never auto,
which stops at i64/u64/f64).
Uint128(u128)
128-bit unsigned — only from the table u128 type.
Float(f64)
String(String)
DateTime(String)
An RFC 3339-style date or datetime, kept as its text. Produced by
toml datetime literals, the table dt type and the auto guess —
all gated by the datetime feature. Serializes as the string itself (so
a serialize→deserialize round trip through a format without a
datetime type yields a String).
Date(String)
YYYY-MM-DD, kept as its text (table date type, date feature).
Time(String)
hh:mm:ss[.fraction], kept as its text (table time type, time
feature).
Ipv4(Ipv4Addr)
Table ipv4 type (ipv4 feature); serializes canonically. The
inet type (inet feature) also produces this or Value::Ipv6,
whichever family parses.
Ipv6(Ipv6Addr)
Table ipv6 type (ipv6 feature); serializes canonically.
Inet(String)
A host address with a netmask (10.0.0.1/24), kept as its
validated text — PostgreSQL inet semantics, host bits below the
mask may be set (table inet type, inet feature; a bare inet
address maps onto Value::Ipv4/Value::Ipv6 instead).
Cidr(String)
A network — optional netmask defaulting to the full address
length, host bits below the mask must be zero — kept as its
validated text; PostgreSQL cidr semantics (table cidr type,
cidr feature).
MacAddr(String)
6-byte MAC address, kept as its validated text (table macaddr
type, macaddr feature).
MacAddr8(String)
8-byte MAC address, kept as its validated text (table macaddr8
type, macaddr8 feature).
Uuid(String)
Hyphenated 8-4-4-4-12 UUID, kept as its validated text (table
uuid type, uuid feature).
Array(Vec<Value>)
Object(BTreeMap<String, Value>)
Implementations§
Source§impl Value
impl Value
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
Object member by key; None when this is not an object or the key
is absent.
Sourcepub fn get_index(&self, index: usize) -> Option<&Value>
pub fn get_index(&self, index: usize) -> Option<&Value>
Array element by index; None when this is not an array or the
index is out of bounds.
pub fn is_null(&self) -> bool
pub fn as_bool(&self) -> Option<bool>
pub fn as_i64(&self) -> Option<i64>
pub fn as_u64(&self) -> Option<u64>
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
The text of a string — or of a datetime/date/time value, which keep their text form.
Sourcepub fn format_id(&self) -> Cow<'static, str>
pub fn format_id(&self) -> Cow<'static, str>
The format id of this value — which parser produced it: null,
bool, i64, u64, i128, u128, f64, str, the typed ids (dt, date,
time, ipv4, ipv6, cidr, macaddr, macaddr8, uuid),
arr:<t> for homogeneous scalar arrays, arr for other arrays,
object for objects. Integer widths normalize to the stored type
(an i8 cell stores an i64, so it reports i64), and inet
reports as the family it parsed into. Shown by trace() as the
format field of every serialized leaf.
pub fn as_array(&self) -> Option<&Vec<Value>>
pub fn as_object(&self) -> Option<&BTreeMap<String, Value>>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Index<&str> for Value
value["key"] — yields Value::Null for missing keys or non-objects,
so lookups chain without panicking: value["db"]["port"].as_u64().
impl Index<&str> for Value
value["key"] — yields Value::Null for missing keys or non-objects,
so lookups chain without panicking: value["db"]["port"].as_u64().