pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
String(String),
Sequence(Vec<Self>),
Mapping(Mapping),
}Expand description
A parsed YAML value.
Variants§
Null
null, ~, or an empty value.
Bool(bool)
true / false.
Int(i64)
An integer scalar.
Float(f64)
A floating-point scalar.
String(String)
A string scalar.
Sequence(Vec<Self>)
A sequence ([...] or block - ...).
Mapping(Mapping)
A mapping ({...} or block key: value).
Implementations§
Source§impl Value
impl Value
Sourcepub fn to_yaml_string(&self) -> String
pub fn to_yaml_string(&self) -> String
Emits this value as YAML text using block style, preserving key order.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns the string contents if this is a Value::String.
Sourcepub const fn as_bool(&self) -> Option<bool>
pub const fn as_bool(&self) -> Option<bool>
Returns the boolean if this is a Value::Bool.
Sourcepub const fn as_int(&self) -> Option<i64>
pub const fn as_int(&self) -> Option<i64>
Returns the integer if this is a Value::Int.
Sourcepub const fn as_float(&self) -> Option<f64>
pub const fn as_float(&self) -> Option<f64>
Returns the floating-point number if this is a Value::Float.
Sourcepub fn as_sequence(&self) -> Option<&[Self]>
pub fn as_sequence(&self) -> Option<&[Self]>
Returns the sequence elements if this is a Value::Sequence.
Sourcepub const fn as_mapping(&self) -> Option<&Mapping>
pub const fn as_mapping(&self) -> Option<&Mapping>
Returns the mapping if this is a Value::Mapping.
Sourcepub const fn is_empty_value(&self) -> bool
pub const fn is_empty_value(&self) -> bool
True for Null, an empty string, an empty sequence, or an empty
mapping. Mirrors Python’s “falsy” check used by the reference
implementation’s validate() (not frontmatter.get(k)).
Sourcepub fn as_display_string(&self) -> Option<String>
pub fn as_display_string(&self) -> Option<String>
Renders a scalar as a plain display string (used for typed frontmatter
accessors that coerce scalars to text, matching the reference’s
str(fm.get(...))).
Sourcepub fn as_display_str(&self) -> Option<Cow<'_, str>>
pub fn as_display_str(&self) -> Option<Cow<'_, str>>
The borrowing form of as_display_string:
returns a std::borrow::Cow borrowing the String case and
owning the coerced form for Bool/Int/
Float. None for non-scalar variants.
Frontmatter accessors use this so the common case (a YAML string) is
allocation-free, while the deviation case (e.g. type: 42) still
coerces to text the way the reference’s str(fm.get(...)) does, rather
than silently reading as None.