Value

Enum Value 

Source
pub enum Value {
    Null,
    Bool(bool),
    Int(i64),
    Float(f64),
    String(String),
    Sequence(Vec<Value>),
    Mapping(IndexMap<Value, Value>),
}
Expand description

A YAML value with all possible types

Variants§

§

Null

Null value

§

Bool(bool)

Boolean value

§

Int(i64)

Integer value

§

Float(f64)

Floating point value

§

String(String)

String value

§

Sequence(Vec<Value>)

Sequence (array/list) value

§

Mapping(IndexMap<Value, Value>)

Mapping (dictionary/object) value

Implementations§

Source§

impl Value

Source

pub const fn null() -> Self

Create a null value

Source

pub const fn bool(b: bool) -> Self

Create a boolean value

Source

pub const fn int(i: i64) -> Self

Create an integer value

Source

pub const fn float(f: f64) -> Self

Create a float value

Source

pub fn string(s: impl Into<String>) -> Self

Create a string value

Source

pub const fn sequence() -> Self

Create an empty sequence

Source

pub const fn sequence_with(values: Vec<Self>) -> Self

Create a sequence with values

Source

pub fn mapping() -> Self

Create an empty mapping

Source

pub fn mapping_with(pairs: Vec<(Self, Self)>) -> Self

Create a mapping with key-value pairs

Source

pub const fn type_name(&self) -> &'static str

Get the type name of this value

Source

pub const fn is_null(&self) -> bool

Check if this value is null

Source

pub const fn is_bool(&self) -> bool

Check if this value is a boolean

Source

pub const fn is_int(&self) -> bool

Check if this value is an integer

Source

pub const fn is_float(&self) -> bool

Check if this value is a float

Source

pub const fn is_string(&self) -> bool

Check if this value is a string

Source

pub const fn is_sequence(&self) -> bool

Check if this value is a sequence

Source

pub const fn is_mapping(&self) -> bool

Check if this value is a mapping

Source

pub const fn is_number(&self) -> bool

Check if this value is a number (int or float)

Source

pub fn len(&self) -> Option<usize>

Get the length of sequences and mappings, None for scalars

Source

pub fn is_empty(&self) -> bool

Check if sequences, mappings, or strings are empty

Source

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

Get this value as a boolean, if possible

Source

pub const fn as_int(&self) -> Option<i64>

Get this value as an integer, if possible

Source

pub const fn as_float(&self) -> Option<f64>

Get this value as a float, if possible

Source

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

Get this value as a string reference, if possible

Source

pub const fn as_sequence(&self) -> Option<&Vec<Self>>

Get this value as a sequence reference, if possible

Source

pub const fn as_sequence_mut(&mut self) -> Option<&mut Vec<Self>>

Get this value as a mutable sequence reference, if possible

Source

pub const fn as_mapping(&self) -> Option<&IndexMap<Self, Self>>

Get this value as a mapping reference, if possible

Source

pub const fn as_mapping_mut(&mut self) -> Option<&mut IndexMap<Self, Self>>

Get this value as a mutable mapping reference, if possible

Source

pub fn get(&self, index: &Self) -> Option<&Self>

Index into a sequence or mapping

Source

pub fn get_str(&self, key: &str) -> Option<&Self>

Convenience method to get a value by string key

Source

pub fn get_index(&self, index: usize) -> Option<&Self>

Get a value by numeric index (for sequences)

Source

pub fn get_mut(&mut self, index: &Self) -> Option<&mut Self>

Mutably index into a sequence or mapping

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · 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 Display for Value

Source§

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

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

impl From<&str> for Value

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<()> for Value

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl From<BorrowedValue<'_>> for Value

Source§

fn from(value: BorrowedValue<'_>) -> Self

Converts to this type from the input type.
Source§

impl From<IndexMap<Value, Value>> for Value

Source§

fn from(map: IndexMap<Self, Self>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Value> for BorrowedValue<'a>

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for CommentedValue

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(seq: Vec<Self>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(f: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(f: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(i: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(i: i64) -> Self

Converts to this type from the input type.
Source§

impl Hash for Value

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Value

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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 Eq 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 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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.