Skip to main content

Value

Enum Value 

Source
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

Source

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.

Source

pub fn is_null(&self) -> bool

Source

pub fn is_bool(&self) -> bool

Source

pub fn as_bool(&self) -> Option<bool>

Source

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.

Source

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.

Source

pub fn as_unsigned(&self) -> Option<u64>

Source

pub fn is_float(&self) -> bool

True for Float, and for a Value::Number literal with a fractional part or exponent.

Source

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.

Source

pub fn is_number_literal(&self) -> bool

True for a Value::Number literal (a number outside Integer/Unsigned/Float’s exact range, preserved verbatim).

Source

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.

Source

pub fn is_string(&self) -> bool

Source

pub fn as_str(&self) -> Option<&str>

Source

pub fn is_array(&self) -> bool

Source

pub fn as_array(&self) -> Option<&Vec<Value>>

Source

pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>

Source

pub fn is_object(&self) -> bool

Source

pub fn as_object(&self) -> Option<&BTreeMap<String, Value>>

Source

pub fn as_object_mut(&mut self) -> Option<&mut BTreeMap<String, Value>>

Source

pub fn get(&self, key: &str) -> Option<&Value>

Source

pub fn get_mut(&mut self, key: &str) -> Option<&mut Value>

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 Display for Value

Source§

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

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

impl From<Value> for Value

Source§

fn from(v: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(v: Value) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> 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
Source§

impl StructuralPartialEq for Value

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more