Enum Scalar

Source
pub enum Scalar<'input> {
    Null,
    Boolean(bool),
    Integer(i64),
    FloatingPoint(OrderedFloat<f64>),
    String(Cow<'input, str>),
}
Expand description

The resolved value of a scalar YAML node.

Scalar nodes are any leaf nodes when parsing YAML. In the 10.1 Failsafe Schema, they would represent any !!str node.

Variants§

§

Null

A null value (10.2.1.1 Null).

§

Boolean(bool)

A boolean value (10.2.1.2 Boolean).

§

Integer(i64)

An integer value (10.2.1.3 Integer).

§

FloatingPoint(OrderedFloat<f64>)

A floating point value (10.2.1.4 Floating Point).

§

String(Cow<'input, str>)

A string (10.1.1.3 Generic String).

This variant is used when representing the node in any other representation fails.

Implementations§

Source§

impl<'input> Scalar<'input>

Source

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

Get a copy of the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some($t) with a copy of the $t contained. Otherwise, return None.

Source

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

Get a copy of the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some($t) with a copy of the $t contained. Otherwise, return None.

Source

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

Get a copy of the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some($t) with a copy of the $t contained. Otherwise, return None.

Source

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

Get a reference to the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some(&$t) with the $t contained. Otherwise, return None.

Source

pub fn as_bool_mut(&mut self) -> Option<&mut bool>

Get a mutable reference to the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some(&mut $t) with the $t contained. Otherwise, return None.

Source

pub fn as_integer_mut(&mut self) -> Option<&mut i64>

Get a mutable reference to the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some(&mut $t) with the $t contained. Otherwise, return None.

Source

pub fn as_floating_point_mut(&mut self) -> Option<&mut f64>

Get a mutable reference to the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some(&mut $t) with the $t contained. Otherwise, return None.

Source

pub fn into_boolean(self) -> Option<bool>

Get the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some($t) with the $t contained. Otherwise, return None.

Source

pub fn into_i64(self) -> Option<i64>

Get the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some($t) with the $t contained. Otherwise, return None.

Source

pub fn into_f64(self) -> Option<f64>

Get the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some($t) with the $t contained. Otherwise, return None.

Source

pub fn into_string(self) -> Option<String>

Get the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some($t) with the $t contained. Otherwise, return None.

Source

pub fn is_null(&self) -> bool

Check whether the YAML enum contains the given variant.

§Return

If the variant of self is Self::$variant, return true. Otherwise, return false.

Source

pub fn is_boolean(&self) -> bool

Check whether the YAML enum contains the given variant.

§Return

If the variant of self is Self::$variant, return true. Otherwise, return false.

Source

pub fn is_integer(&self) -> bool

Check whether the YAML enum contains the given variant.

§Return

If the variant of self is Self::$variant, return true. Otherwise, return false.

Source

pub fn is_floating_point(&self) -> bool

Check whether the YAML enum contains the given variant.

§Return

If the variant of self is Self::$variant, return true. Otherwise, return false.

Source

pub fn is_string(&self) -> bool

Check whether the YAML enum contains the given variant.

§Return

If the variant of self is Self::$variant, return true. Otherwise, return false.

Source

pub fn as_cow(&self) -> Option<&Cow<'input, str>>

Get a reference to the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some(&$t) with the $t contained. Otherwise, return None.

Source

pub fn as_cow_mut(&mut self) -> Option<&mut Cow<'input, str>>

Get a mutable reference to the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some(&mut $t) with the $t contained. Otherwise, return None.

Source

pub fn into_cow(self) -> Option<Cow<'input, str>>

Get the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some($t) with the $t contained. Otherwise, return None.

Source

pub fn as_str_mut(&mut self) -> Option<&mut str>

Get a mutable reference to the inner object in the YAML enum if it is a $t.

§Return

If the variant of self is Self::$variant, return Some(&mut $t) with the $t contained. Otherwise, return None.

Source

pub fn into_owned(self) -> ScalarOwned

Take ownership of self and turn it into a ScalarOwned.

Source

pub fn parse_from_cow_and_metadata( v: Cow<'input, str>, style: ScalarStyle, tag: Option<&Tag>, ) -> Option<Self>

Parse a scalar node representation into a Scalar.

§Return

Returns the parsed Scalar.

If tag is not None and v cannot be parsed as that specific tag, this function returns None.

§Examples
assert_eq!(
    Scalar::parse_from_cow_and_metadata("123".into(), ScalarStyle::Plain, None),
    Some(Scalar::Integer(123))
);
assert_eq!(
    Scalar::parse_from_cow_and_metadata(
        "123".into(),
        ScalarStyle::Plain,
        Some(&Tag { handle: "tag:yaml.org,2002:".into(), suffix: "str".into() })
    ),
    Some(Scalar::String("123".into()))
);
assert_eq!(
    Scalar::parse_from_cow_and_metadata(
        "not a number".into(),
        ScalarStyle::Plain,
        Some(&Tag { handle: "tag:yaml.org,2002:".into(), suffix: "int".into() })
    ),
    None
);
assert_eq!(
    Scalar::parse_from_cow_and_metadata(
        "No".into(),
        ScalarStyle::Plain,
        Some(&Tag { handle: "tag:yaml.org,2002:".into(), suffix: "bool".into() })
    ),
    None
);
Source

pub fn parse_from_cow(v: Cow<'input, str>) -> Self

Parse a scalar node representation into a Scalar.

This function cannot fail. It will fallback to Scalar::String if everything else fails.

§Return

Returns the parsed Scalar.

Trait Implementations§

Source§

impl<'input> Clone for Scalar<'input>

Source§

fn clone(&self) -> Scalar<'input>

Returns a copy 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<'input> Debug for Scalar<'input>

Source§

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

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

impl<'input> Hash for Scalar<'input>

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<'input> Ord for Scalar<'input>

Source§

fn cmp(&self, other: &Scalar<'input>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'input> PartialEq for Scalar<'input>

Source§

fn eq(&self, other: &Scalar<'input>) -> 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<'input> PartialOrd for Scalar<'input>

Source§

fn partial_cmp(&self, other: &Scalar<'input>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'input> Eq for Scalar<'input>

Source§

impl<'input> StructuralPartialEq for Scalar<'input>

Auto Trait Implementations§

§

impl<'input> Freeze for Scalar<'input>

§

impl<'input> RefUnwindSafe for Scalar<'input>

§

impl<'input> Send for Scalar<'input>

§

impl<'input> Sync for Scalar<'input>

§

impl<'input> Unpin for Scalar<'input>

§

impl<'input> UnwindSafe for Scalar<'input>

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