Skip to main content

Value

Enum Value 

Source
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

Source

pub fn parse(text: &str) -> Result<Self, YamlError>

Parses a single YAML value from text (the OKF frontmatter subset).

§Errors

Returns YamlError for any input outside the supported subset (anchors, tags, multiple documents, or syntactically malformed YAML).

Source

pub fn to_yaml_string(&self) -> String

Emits this value as YAML text using block style, preserving key order.

Source

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

Returns the string contents if this is a Value::String.

Source

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

Returns the boolean if this is a Value::Bool.

Source

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

Returns the integer if this is a Value::Int.

Source

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

Returns the floating-point number if this is a Value::Float.

Source

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

Returns the sequence elements if this is a Value::Sequence.

Source

pub const fn as_mapping(&self) -> Option<&Mapping>

Returns the mapping if this is a Value::Mapping.

Source

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

Source

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

Source

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.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

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 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<&String> for Value

Source§

fn from(s: &String) -> Self

Converts to this type from the input type.
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<Cow<'_, str>> for Value

Source§

fn from(s: Cow<'_, str>) -> Self

Converts to this type from the input type.
Source§

impl From<Mapping> for Value

Source§

fn from(m: Mapping) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Self>> From<Option<T>> for Value

Source§

fn from(opt: Option<T>) -> 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<T: Into<Self>> From<Vec<T>> for Value

Source§

fn from(v: Vec<T>) -> 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<i8> for Value

Source§

fn from(i: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(i: i16) -> 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 From<u8> for Value

Source§

fn from(u: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(u: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(u: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(u: u64) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Value

Source§

fn from(u: usize) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Value

Source§

type Err = YamlError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Value

Source§

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