Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Object(HashMap<String, Value>),
    Array(Vec<Value>),
    Boolean(bool),
    Null,
    String(String),
    Number(Number),
}

Variants§

§

Object(HashMap<String, Value>)

§

Array(Vec<Value>)

§

Boolean(bool)

§

Null

§

String(String)

§

Number(Number)

Implementations§

Source§

impl Value

Source

pub fn object(obj: HashMap<String, Value>) -> Value

Source

pub fn object_from_iter<I>(iter: I) -> Value
where I: IntoIterator<Item = (String, Value)>,

Source

pub fn array(values: Vec<Value>) -> Value

Source

pub fn array_from_iter<I>(iter: I) -> Value
where I: IntoIterator<Item = Value>,

Source

pub fn boolean(boolean: bool) -> Value

Source

pub fn null() -> Value

Source

pub fn new_string(string: impl Into<String>) -> Value

Source§

impl Value

Source

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

Source

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

Source

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

Source

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

Source

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

Attempts to interpret the current Value as an array by applying HOCON’s “numerically-indexed object to array” conversion rule.

§Behavior
  • If the value is already an array (Value::Array), this simply returns a reference to its elements as a Vec<&Value>.

  • If the value is an object (Value::Object) whose keys are strings representing integers (e.g. "0", "1", "2"), it is converted into an array:

    • Keys are filtered to include only those that can be parsed as usize.
    • The key–value pairs are sorted by their numeric key.
    • The values are collected into a Vec<&Value> in ascending key order.
  • For any other kind of value, the function returns None.

§Example
{
  "0": "first",
  "2": "third",
  "1": "second"
}

Will be interpreted as:

[ "first", "second", "third" ]
Source

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

Attempts to interpret the current Value as a boolean, following HOCON’s relaxed truthy/falsey rules.

§Behavior
  • If the value is a Value::Boolean, returns the inner bool.

  • If the value is a Value::String, accepts several textual representations:

    • "true", "on", "yes" → Some(true)
    • "false", "off", "no" → Some(false)
  • For all other values (numbers, arrays, objects, or strings that don’t match the above), returns None.

§Notes
  • The matching is case-sensitive ("True" will not be recognized).
  • This conversion is specific to HOCON and goes beyond JSON’s strict boolean representation.
Source

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

Source

pub fn as_f64(&self) -> Option<f64>

Source

pub fn as_i64(&self) -> Option<i64>

Source

pub fn as_i128(&self) -> Option<i128>

Source

pub fn as_u128(&self) -> Option<u128>

Source

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

Source

pub fn is_null(&self) -> bool

Checks whether the current Value represents null in HOCON.

§Behavior
  • Returns true if the value is explicitly Value::Null.
  • Returns true if the value is a Value::String equal to "null".
  • Otherwise, returns false.
§Notes
  • The check for "null" is case-sensitive. "Null" or "NULL" will not be considered null.
  • This deviates from strict JSON, where only a literal null is valid. HOCON allows the string "null" to be treated as a null value.
Source

pub fn ty(&self) -> &'static str

Source

pub fn into_object(self) -> Option<HashMap<String, Value>>

Source

pub fn into_array(self) -> Option<Vec<Value>>

Source

pub fn into_boolean(self) -> Option<bool>

Source

pub fn into_string(self) -> Option<String>

Source

pub fn into_number(self) -> Option<Number>

Source

pub fn get_by_path<'a>(&self, paths: impl AsRef<[&'a str]>) -> Option<&Value>

Retrieves a value from a nested Value::Object by following a HOCON-style path.

§Arguments
  • paths - A sequence of keys representing the path to the desired value. The path should already be split by . (dot).
§Returns
  • Some(&Value) if the full path exists in the object tree.
  • None if any key in the path does not exist or if a non-object value is encountered before reaching the end of the path.
§Example
// Assuming the following HOCON-like structure:
// {
//   database: {
//     connection: {
//       timeout: 30
//     }
//   }
// }

let val = root.get_by_path(&["database", "connection", "timeout"]);
assert_eq!(val, Some(&hocon_rs::Value::Number(30.into())));
Source

pub fn get_by_path_mut<'a>( &mut self, paths: impl AsRef<[&'a str]>, ) -> Option<&mut Value>

Source

pub fn with_fallback(self, fallback: Value) -> Value

Merge this Value with a fallback Value, following HOCON’s withFallback semantics.

  • If both self and fallback are Objects, they are merged key by key:
    • If a key exists in both objects:
      • If both values are objects, merge them recursively.
      • Otherwise, keep the value from self (ignore the fallback).
    • If a key exists only in the fallback, insert it into self.
  • For all other cases (non-object values), self takes precedence and the fallback is ignored.
Source§

impl Value

Source

pub fn as_bytes(&self) -> Option<BigUint>

Source

pub fn as_duration(&self) -> Option<Duration>

Source

pub fn as_nanos(&self) -> Option<u128>

Source

pub fn as_millis(&self) -> Option<u128>

Source

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

Source

pub fn as_secs_f32(&self) -> Option<f32>

Source

pub fn as_secs_f64(&self) -> Option<f64>

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

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: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

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

impl<'de> Deserializer<'de> for Value

Source§

type Error = Error

The error type that can be returned if some error occurs during deserialization.
Source§

fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
where V: Visitor<'de>,

Require the Deserializer to figure out how to drive the visitor based on what data type is in the input. Read more
Source§

fn deserialize_bool<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_i8<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_i128<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting an i128 value. Read more
Source§

fn deserialize_u8<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_u128<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting an u128 value. Read more
Source§

fn deserialize_f32<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_char<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a char value.
Source§

fn deserialize_str<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_string<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a string value and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_bytes<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_byte_buf<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a byte array and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_option<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting an optional value. Read more
Source§

fn deserialize_unit<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_unit_struct<W>( self, name: &'static str, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a unit struct with a particular name.
Source§

fn deserialize_newtype_struct<W>( self, name: &'static str, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a newtype struct with a particular name.
Source§

fn deserialize_seq<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values.
Source§

fn deserialize_tuple<W>( self, len: usize, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a sequence of values and knows how many values there are without looking at the serialized data.
Source§

fn deserialize_tuple_struct<W>( self, name: &'static str, len: usize, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a tuple struct with a particular name and number of fields.
Source§

fn deserialize_map<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a map of key-value pairs.
Source§

fn deserialize_struct<W>( self, name: &'static str, fields: &'static [&'static str], visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting a struct with a particular name and fields.
Source§

fn deserialize_enum<W>( self, name: &'static str, variants: &'static [&'static str], visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting an enum value with a particular name and possible variants.
Source§

fn deserialize_identifier<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type is expecting the name of a struct field or the discriminant of an enum variant.
Source§

fn deserialize_ignored_any<W>( self, visitor: W, ) -> Result<W::Value, <Self as Deserializer<'de>>::Error>
where W: Visitor<'de>,

Hint that the Deserialize type needs to deserialize a value whose type doesn’t matter because it is ignored. Read more
Source§

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to deserialize their human-readable form. 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 Eq for Value

Source§

impl From<&str> for Value

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<(&str, Value)> for Value

Source§

fn from(value: (&str, Value)) -> Self

Converts to this type from the input type.
Source§

impl From<(String, Value)> for Value

Source§

fn from(value: (String, Value)) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: HashMap<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl From<Number> for Value

Source§

fn from(value: Number) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for RawValue

Source§

fn from(val: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(val: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(val: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<(&str, Value)>> for Value

Source§

fn from(value: Vec<(&str, Value)>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<(String, Value)>> for Value

Source§

fn from(value: Vec<(String, Value)>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

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

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl<I> Index<I> for Value
where I: Index,

Source§

fn index(&self, index: I) -> &Value

Immutable indexing operator (value[index]).

Returns a reference to the indexed value, or Value::Null if the index is not present or invalid.

Source§

type Output = Value

The returned type after indexing.
Source§

impl<I> IndexMut<I> for Value
where I: Index,

Source§

fn index_mut(&mut self, index: I) -> &mut Value

Mutable indexing operator (value[index] = ...).

Will insert new entries for string keys into objects. For usize indices, will panic if the index is out of bounds. Panics if the type of the value does not match the index type.

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>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

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> ErasedDestructor for T
where T: 'static,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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