Skip to main content

YamlValue

Enum YamlValue 

Source
pub enum YamlValue {
    Scalar(ScalarValue),
    Sequence(Vec<YamlValue>),
    Mapping(BTreeMap<String, YamlValue>),
    Set(BTreeSet<String>),
    OrderedMapping(Vec<(String, YamlValue)>),
    Pairs(Vec<(String, YamlValue)>),
}
Expand description

Represents any YAML value - scalar, sequence, mapping, or special collections.

Deprecated: Prefer using syntax tree types (Mapping, Sequence, Scalar) and the AsYaml trait instead - they preserve formatting and work with the CST directly. YamlValue loses all formatting information.

Variants§

§

Scalar(ScalarValue)

A scalar value (string, number, boolean, null)

§

Sequence(Vec<YamlValue>)

A sequence of values (list/array)

§

Mapping(BTreeMap<String, YamlValue>)

A mapping of key-value pairs

§

Set(BTreeSet<String>)

A set of unique values (!!set)

§

OrderedMapping(Vec<(String, YamlValue)>)

An ordered mapping preserving key order (!!omap)

§

Pairs(Vec<(String, YamlValue)>)

A sequence of key-value pairs allowing duplicates (!!pairs)

Implementations§

Source§

impl YamlValue

Source

pub fn cast(node: SyntaxNode<Lang>) -> Option<Self>

Try to cast a SyntaxNode to a YamlValue

Source

pub fn scalar(value: impl Into<ScalarValue>) -> Self

Create a scalar value

Source

pub const fn sequence() -> Self

Create an empty sequence

Source

pub const fn from_sequence(items: Vec<YamlValue>) -> Self

Create a sequence from a vector

Source

pub const fn mapping() -> Self

Create an empty mapping

Source

pub fn parse_raw(yaml_str: &str) -> Self

Parse a raw YAML string into a YamlValue This handles both simple scalars and complex structures

Source

pub fn from_document(doc: &Document) -> Self

Convert a Document to a YamlValue

Source

pub const fn from_mapping(map: BTreeMap<String, YamlValue>) -> Self

Create a mapping from a BTreeMap

Source

pub const fn set() -> Self

Create an empty set

Source

pub const fn from_set(set: BTreeSet<String>) -> Self

Create a set from a BTreeSet

Source

pub const fn ordered_mapping() -> Self

Create an empty ordered mapping

Source

pub const fn from_ordered_mapping(pairs: Vec<(String, YamlValue)>) -> Self

Create an ordered mapping from a vector of pairs

Source

pub const fn pairs() -> Self

Create empty pairs

Source

pub const fn from_pairs(pairs: Vec<(String, YamlValue)>) -> Self

Create pairs from a vector of pairs

Source

pub fn is_scalar(&self) -> bool

Return true if this value is a scalar (string, integer, float, bool, null, etc.).

Use as_scalar to access the inner ScalarValue.

Source

pub fn is_sequence(&self) -> bool

Return true if this value is a sequence (YAML list / array).

Use as_sequence to access the inner sequence.

Source

pub fn is_mapping(&self) -> bool

Return true if this value is a plain mapping (key: value pairs).

Use as_mapping to access the inner mapping.

Source

pub fn is_set(&self) -> bool

Return true if this value is a !!set tagged collection.

Source

pub fn is_ordered_mapping(&self) -> bool

Return true if this value is a !!omap (ordered mapping) tagged collection.

Source

pub fn is_pairs(&self) -> bool

Return true if this value is a !!pairs tagged collection.

Source

pub fn as_scalar(&self) -> Option<&ScalarValue>

Get as scalar if this is a scalar

Source

pub fn as_sequence(&self) -> Option<&[YamlValue]>

Get as sequence if this is a sequence

Source

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

Get as mutable sequence if this is a sequence

Source

pub fn as_mapping(&self) -> Option<&BTreeMap<String, YamlValue>>

Get as mapping if this is a mapping

Source

pub fn as_mapping_mut(&mut self) -> Option<&mut BTreeMap<String, YamlValue>>

Get as mutable mapping if this is a mapping

Source

pub fn as_set(&self) -> Option<&BTreeSet<String>>

Get as set if this is a set

Source

pub fn as_set_mut(&mut self) -> Option<&mut BTreeSet<String>>

Get as mutable set if this is a set

Source

pub fn as_ordered_mapping(&self) -> Option<&[(String, YamlValue)]>

Get as ordered mapping if this is an ordered mapping

Source

pub fn as_ordered_mapping_mut( &mut self, ) -> Option<&mut Vec<(String, YamlValue)>>

Get as mutable ordered mapping if this is an ordered mapping

Source

pub fn as_pairs(&self) -> Option<&[(String, YamlValue)]>

Get as pairs if this is pairs

Source

pub fn as_pairs_mut(&mut self) -> Option<&mut Vec<(String, YamlValue)>>

Get as mutable pairs if this is pairs

Source

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

Get a reference to the string value if this is a scalar

Returns the string representation of the scalar value. Returns None for non-scalar types (mappings, sequences, etc). Note: All scalars can be represented as strings, regardless of their type.

Source

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

Try to convert this value to an i64

Returns the integer value if this is a scalar with Integer type. Supports various formats (decimal, hexadecimal 0x, binary 0b, octal 0o). Returns None if this is not a scalar or not an integer type.

Note: This respects YAML’s type system - 42 (unquoted) is an integer, but "42" (quoted) is a string and will return None.

Source

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

Try to convert this value to an f64

Returns the float value if this is a scalar with Float type. Returns None if this is not a scalar or not a float type.

Note: This respects YAML’s type system - 3.14 (unquoted) is a float, but "3.14" (quoted) is a string and will return None.

Source

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

Try to convert this value to a bool

Returns the boolean value if this is a scalar with Boolean type. Recognizes: true, false, yes, no, on, off (case-insensitive). Returns None if this is not a scalar or not a boolean type.

Note: This respects YAML’s type system - no (unquoted) is boolean, but "no" (quoted) is a string and will return None.

Source

pub fn to_yaml_string(&self, indent: usize) -> String

Convert to YAML string representation

Trait Implementations§

Source§

impl AsYaml for YamlValue

Source§

fn as_node(&self) -> Option<&SyntaxNode<Lang>>

Returns a reference to the underlying SyntaxNode if one exists. Read more
Source§

fn kind(&self) -> YamlKind

Returns the kind of YAML value this represents.
Source§

fn build_content( &self, builder: &mut GreenNodeBuilder<'_>, indent: usize, flow_context: bool, ) -> bool

Serialize this value into a GreenNodeBuilder. Read more
Source§

fn is_inline(&self) -> bool

Returns whether this value should be rendered on the same line as its key. Read more
Source§

impl Clone for YamlValue

Source§

fn clone(&self) -> YamlValue

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 YamlValue

Source§

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

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

impl Display for YamlValue

Source§

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

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

impl Eq for YamlValue

Source§

impl From<&YamlValue> for YamlValue

Source§

fn from(value: &YamlValue) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for YamlValue

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl<K, V> From<BTreeMap<K, V>> for YamlValue
where K: Into<String>, V: Into<YamlValue>,

Source§

fn from(map: BTreeMap<K, V>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<BTreeSet<T>> for YamlValue
where T: Into<String>,

Source§

fn from(set: BTreeSet<T>) -> Self

Converts to this type from the input type.
Source§

impl From<ScalarValue> for YamlValue

Source§

fn from(value: ScalarValue) -> Self

Converts to this type from the input type.
Source§

impl From<String> for YamlValue

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for YamlValue
where T: Into<YamlValue>,

Source§

fn from(vec: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for YamlValue

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for YamlValue

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for YamlValue

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for YamlValue

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for YamlValue

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for YamlValue

Source§

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

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

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.