Skip to main content

HoconValue

Enum HoconValue 

Source
#[non_exhaustive]
pub enum HoconValue { Object(IndexMap<String, HoconValue>), Array(Vec<HoconValue>), Scalar(ScalarValue), }
Expand description

A resolved HOCON value.

This is the tree that Config wraps. You normally interact with it through the typed getters on Config, but it is also returned directly by Config::get and Config::get_list.

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.
§

Object(IndexMap<String, HoconValue>)

An ordered map of key-value pairs (HOCON object / JSON object).

§

Array(Vec<HoconValue>)

An ordered list of values (HOCON array / JSON array).

§

Scalar(ScalarValue)

A leaf value (string, number, boolean, or null).

Implementations§

Source§

impl HoconValue

Source

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

The string, if this is a string scalar.

Strict: numbers/booleans/null return None (mirrors serde_json::Value::as_str). For coercing any scalar to text, use Config::get_string.

Source

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

This value as i64, if it is a scalar coercible to one.

HOCON-aware coercion matching Config::get_i64: a quoted "8080" and a bare 8080 both yield Some(8080), and a whole-number numeric scalar (1.0, 1e3) is truncated to its integer value. A non-whole number (1.5) yields None.

Source

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

This value as f64, if it is a scalar whose raw text parses as one.

Source

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

This value as bool, if it is a scalar with a recognised boolean spelling.

Accepts true/yes/on and false/no/off (case-insensitive), matching the serde boolean coercion.

Source

pub fn as_object(&self) -> Option<&IndexMap<String, HoconValue>>

The underlying ordered map, if this is an object.

Source

pub fn as_array(&self) -> Option<&[HoconValue]>

The underlying slice, if this is an array.

Structural: a numeric-keyed object is not coerced to an array here (unlike Config::get_list / serde sequence deserialization). Use get_as::<Vec<_>> / from_value::<Vec<_>> for that.

Source

pub fn is_object(&self) -> bool

Whether this value is an object.

Source

pub fn is_array(&self) -> bool

Whether this value is an array.

Source

pub fn is_scalar(&self) -> bool

Whether this value is a scalar (string, number, boolean, or null).

Source

pub fn is_null(&self) -> bool

Whether this value is an explicit null scalar.

Trait Implementations§

Source§

impl Clone for HoconValue

Source§

fn clone(&self) -> HoconValue

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 HoconValue

Source§

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

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

impl PartialEq for HoconValue

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for HoconValue

Auto Trait Implementations§

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> 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.