pub struct Scalar(/* private fields */);Expand description
A YAML scalar value
Note: This type uses interior mutability through the rowan library.
Mutation methods work even when called through &self. See the crate-level
documentation for details on the mutability model.
Implementations§
Source§impl Scalar
impl Scalar
Sourcepub fn as_string(&self) -> String
pub fn as_string(&self) -> String
Get the string representation of this scalar, properly unquoted and unescaped
Sourcepub fn unquoted_value(&self) -> String
pub fn unquoted_value(&self) -> String
Get the raw content of this scalar with outer quotes stripped, but without processing any escape sequences.
For most purposes as_string is more appropriate as
it fully unescapes double-quoted strings (\", \\, \n, etc.) and
handles the '' → ' escape in single-quoted strings. Use this method
only when you need the verbatim content without escape processing.
Source§impl Scalar
impl Scalar
Sourcepub fn set_value(&self, value: &str)
pub fn set_value(&self, value: &str)
Replace the text content of this scalar with value.
The token is stored with SyntaxKind::STRING regardless of the semantic
type of value (e.g., setting "42" does not produce an INT token).
If token-kind accuracy matters, build a replacement scalar node via the
higher-level API instead.
Sourcepub fn byte_range(&self) -> TextPosition
pub fn byte_range(&self) -> TextPosition
Get the byte offset range of this scalar in the source text.
Returns the start and end byte offsets as a TextPosition.
Sourcepub fn start_position(&self, source_text: &str) -> LineColumn
pub fn start_position(&self, source_text: &str) -> LineColumn
Get the line and column where this scalar starts.
Requires the original source text to calculate line/column from byte offsets. Line and column numbers are 1-indexed.
§Arguments
source_text- The original YAML source text
Sourcepub fn end_position(&self, source_text: &str) -> LineColumn
pub fn end_position(&self, source_text: &str) -> LineColumn
Get the line and column where this scalar ends.
Requires the original source text to calculate line/column from byte offsets. Line and column numbers are 1-indexed.
§Arguments
source_text- The original YAML source text
Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Try to interpret this scalar as an i64.
Returns None if the scalar is not a plain YAML 1.2 integer (decimal,
0o octal or 0x hexadecimal) or does not fit in an i64.
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Try to interpret this scalar as an f64.
Returns None if the scalar is not a plain YAML 1.2 float or
integer.
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Try to interpret this scalar as a bool.
Returns None if the scalar is not a plain YAML 1.2 boolean: true,
True, TRUE, false, False or FALSE.
Trait Implementations§
Source§impl AsYaml for Scalar
impl AsYaml for Scalar
Source§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
The continuation lines of a multi-line plain or quoted scalar are
shifted as for a flow collection, keeping their offset from the
indentation of the line the scalar starts on, which becomes
indent. Leading whitespace on those lines is not content, so the
value is unchanged. A block scalar is copied as is: its body is laid
out by the caller, and its indentation can be content.
impl Eq for Scalar
Source§impl From<Scalar> for ScalarValue
Same as ScalarValue::from_scalar.
impl From<Scalar> for ScalarValue
Same as ScalarValue::from_scalar.