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
impl YamlValue
Sourcepub fn cast(node: SyntaxNode<Lang>) -> Option<Self>
pub fn cast(node: SyntaxNode<Lang>) -> Option<Self>
Try to cast a SyntaxNode to a YamlValue
Sourcepub fn scalar(value: impl Into<ScalarValue>) -> Self
pub fn scalar(value: impl Into<ScalarValue>) -> Self
Create a scalar value
Sourcepub const fn from_sequence(items: Vec<YamlValue>) -> Self
pub const fn from_sequence(items: Vec<YamlValue>) -> Self
Create a sequence from a vector
Sourcepub fn parse_raw(yaml_str: &str) -> Self
pub fn parse_raw(yaml_str: &str) -> Self
Parse a raw YAML string into a YamlValue This handles both simple scalars and complex structures
Sourcepub fn from_document(doc: &Document) -> Self
pub fn from_document(doc: &Document) -> Self
Convert a Document to a YamlValue
Sourcepub const fn from_mapping(map: BTreeMap<String, YamlValue>) -> Self
pub const fn from_mapping(map: BTreeMap<String, YamlValue>) -> Self
Create a mapping from a BTreeMap
Sourcepub const fn ordered_mapping() -> Self
pub const fn ordered_mapping() -> Self
Create an empty ordered mapping
Sourcepub const fn from_ordered_mapping(pairs: Vec<(String, YamlValue)>) -> Self
pub const fn from_ordered_mapping(pairs: Vec<(String, YamlValue)>) -> Self
Create an ordered mapping from a vector of pairs
Sourcepub const fn from_pairs(pairs: Vec<(String, YamlValue)>) -> Self
pub const fn from_pairs(pairs: Vec<(String, YamlValue)>) -> Self
Create pairs from a vector of pairs
Sourcepub fn is_scalar(&self) -> bool
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.
Sourcepub fn is_sequence(&self) -> bool
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.
Sourcepub fn is_mapping(&self) -> bool
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.
Sourcepub fn is_ordered_mapping(&self) -> bool
pub fn is_ordered_mapping(&self) -> bool
Return true if this value is a !!omap (ordered mapping) tagged collection.
Sourcepub fn as_scalar(&self) -> Option<&ScalarValue>
pub fn as_scalar(&self) -> Option<&ScalarValue>
Get as scalar if this is a scalar
Sourcepub fn as_sequence(&self) -> Option<&[YamlValue]>
pub fn as_sequence(&self) -> Option<&[YamlValue]>
Get as sequence if this is a sequence
Sourcepub fn as_sequence_mut(&mut self) -> Option<&mut Vec<YamlValue>>
pub fn as_sequence_mut(&mut self) -> Option<&mut Vec<YamlValue>>
Get as mutable sequence if this is a sequence
Sourcepub fn as_mapping(&self) -> Option<&BTreeMap<String, YamlValue>>
pub fn as_mapping(&self) -> Option<&BTreeMap<String, YamlValue>>
Get as mapping if this is a mapping
Sourcepub fn as_mapping_mut(&mut self) -> Option<&mut BTreeMap<String, YamlValue>>
pub fn as_mapping_mut(&mut self) -> Option<&mut BTreeMap<String, YamlValue>>
Get as mutable mapping if this is a mapping
Sourcepub fn as_set_mut(&mut self) -> Option<&mut BTreeSet<String>>
pub fn as_set_mut(&mut self) -> Option<&mut BTreeSet<String>>
Get as mutable set if this is a set
Sourcepub fn as_ordered_mapping(&self) -> Option<&[(String, YamlValue)]>
pub fn as_ordered_mapping(&self) -> Option<&[(String, YamlValue)]>
Get as ordered mapping if this is an ordered mapping
Sourcepub fn as_ordered_mapping_mut(
&mut self,
) -> Option<&mut Vec<(String, YamlValue)>>
pub fn as_ordered_mapping_mut( &mut self, ) -> Option<&mut Vec<(String, YamlValue)>>
Get as mutable ordered mapping if this is an ordered mapping
Sourcepub fn as_pairs_mut(&mut self) -> Option<&mut Vec<(String, YamlValue)>>
pub fn as_pairs_mut(&mut self) -> Option<&mut Vec<(String, YamlValue)>>
Get as mutable pairs if this is pairs
Sourcepub fn as_str(&self) -> Option<&str>
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.
Sourcepub fn to_i64(&self) -> Option<i64>
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.
Sourcepub fn to_f64(&self) -> Option<f64>
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.
Sourcepub fn to_bool(&self) -> Option<bool>
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.
Sourcepub fn to_yaml_string(&self, indent: usize) -> String
pub fn to_yaml_string(&self, indent: usize) -> String
Convert to YAML string representation
Trait Implementations§
Source§impl AsYaml for YamlValue
impl AsYaml for YamlValue
Source§fn as_node(&self) -> Option<&SyntaxNode<Lang>>
fn as_node(&self) -> Option<&SyntaxNode<Lang>>
SyntaxNode if one exists. Read moreSource§fn build_content(
&self,
builder: &mut GreenNodeBuilder<'_>,
indent: usize,
flow_context: bool,
) -> bool
fn build_content( &self, builder: &mut GreenNodeBuilder<'_>, indent: usize, flow_context: bool, ) -> bool
GreenNodeBuilder. Read more