pub enum Value {
Null,
Bool(bool),
Integer(i64),
Unsigned(u64),
Float(f64),
Number(String),
String(String),
Array(Vec<Value>),
Object(BTreeMap<String, Value>),
}Expand description
Custom Value IR independent of any format crate. Supports all formats: JSON, TOML, YAML, dotenv, and INI.
Variants§
Null
Bool(bool)
Integer(i64)
Unsigned(u64)
Float(f64)
Number(String)
A numeric literal that would lose digits if forced through
Value::Integer/Value::Unsigned/Value::Float: an integer
outside u64::MAX, or any literal written with a fractional part or
exponent (3.14, 1e-10, -0.0, …). Holds the exact source text
verbatim — never parsed and reserialized through f64 — so a 30-digit
integer or a high-precision decimal round-trips digit for digit.
Produced by the JSON backend’s reader (format::json::load), which is
the format whose number grammar is genuinely arbitrary-precision;
TOML integers are grammar-limited to i64 and TOML/YAML floats are
canonically f64 at the format level, so those backends keep using
Integer/Unsigned/Float for values in range. set --value-type number also produces this variant, preserving the CLI argument’s
literal spelling the same way.
String(String)
Array(Vec<Value>)
Object(BTreeMap<String, Value>)
Object map. Keys are stored sorted (BTreeMap), not in insertion order.
Implementations§
Source§impl Value
impl Value
Sourcepub const fn kind_name(&self) -> &'static str
pub const fn kind_name(&self) -> &'static str
Stable value-kind label for diagnostics and machine-readable metadata.
Signed and unsigned fixed-width integers both report integer; exact
numeric literals stored in Value::Number report number.
pub fn is_null(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn as_bool(&self) -> Option<bool>
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
True for Integer/Unsigned, and for a Value::Number literal
with no fractional part or exponent — a big integer that only missed
Integer/Unsigned because it overflows i64/u64, not because it
is actually fractional.
Sourcepub fn as_integer(&self) -> Option<i64>
pub fn as_integer(&self) -> Option<i64>
Exact i64 value, when this holds one. None for a Value::Number
literal even when it is integral — by construction that variant only
exists because the literal does not fit i64/u64; read the exact
digits via Value::as_number_literal instead.
pub fn as_unsigned(&self) -> Option<u64>
Sourcepub fn is_float(&self) -> bool
pub fn is_float(&self) -> bool
True for Float, and for a Value::Number literal with a
fractional part or exponent.
Sourcepub fn as_float(&self) -> Option<f64>
pub fn as_float(&self) -> Option<f64>
Best-effort numeric magnitude as f64 — lossy for a
Value::Number literal outside f64’s exact range, but never
fails for a well-formed literal. Callers that need the exact digits
(not just the magnitude) must read Value::as_number_literal
instead; this accessor exists for magnitude-only consumers (numeric
comparisons, lint checks) that cannot use arbitrary precision anyway.
Sourcepub fn is_number_literal(&self) -> bool
pub fn is_number_literal(&self) -> bool
True for a Value::Number literal (a number outside
Integer/Unsigned/Float’s exact range, preserved verbatim).
Sourcepub fn as_number_literal(&self) -> Option<&str>
pub fn as_number_literal(&self) -> Option<&str>
The exact source text of a Value::Number literal, digit for
digit. None for every other variant, including Integer/
Unsigned/Float — those already round-trip exactly through their
own Display, so this accessor is specifically for the literal-only
case where that would corrupt the value.