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>
impl<'input> Scalar<'input>
Sourcepub fn as_bool(&self) -> Option<bool>
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
.
Sourcepub fn as_integer(&self) -> Option<i64>
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
.
Sourcepub fn as_floating_point(&self) -> Option<f64>
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
.
Sourcepub fn as_str(&self) -> Option<&str>
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
.
Sourcepub fn as_bool_mut(&mut self) -> Option<&mut bool>
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
.
Sourcepub fn as_integer_mut(&mut self) -> Option<&mut i64>
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
.
Sourcepub fn as_floating_point_mut(&mut self) -> Option<&mut f64>
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
.
Sourcepub fn into_boolean(self) -> Option<bool>
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
.
Sourcepub fn into_i64(self) -> Option<i64>
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
.
Sourcepub fn into_f64(self) -> Option<f64>
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
.
Sourcepub fn into_string(self) -> Option<String>
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
.
Sourcepub fn is_null(&self) -> bool
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
.
Sourcepub fn is_boolean(&self) -> bool
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
.
Sourcepub fn is_integer(&self) -> bool
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
.
Sourcepub fn is_floating_point(&self) -> bool
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
.
Sourcepub fn is_string(&self) -> bool
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
.
Sourcepub fn as_cow(&self) -> Option<&Cow<'input, str>>
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
.
Sourcepub fn as_cow_mut(&mut self) -> Option<&mut Cow<'input, str>>
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
.
Sourcepub fn into_cow(self) -> Option<Cow<'input, str>>
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
.
Sourcepub fn as_str_mut(&mut self) -> Option<&mut str>
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
.
Sourcepub fn into_owned(self) -> ScalarOwned
pub fn into_owned(self) -> ScalarOwned
Take ownership of self
and turn it into a ScalarOwned
.
Sourcepub fn parse_from_cow_and_metadata(
v: Cow<'input, str>,
style: ScalarStyle,
tag: Option<&Tag>,
) -> Option<Self>
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
);
Sourcepub fn parse_from_cow(v: Cow<'input, str>) -> Self
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
.