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 quoted (string type) or cannot be parsed as an integer.
Supports decimal, octal (0o), hexadecimal (0x), and binary (0b) notation.
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 quoted (string type) or cannot be parsed as a float.
Trait Implementations§
Source§impl AsYaml for Scalar
impl AsYaml for Scalar
Source§fn as_node(&self) -> Option<&SyntaxNode<Lang>>
fn as_node(&self) -> Option<&SyntaxNode<Lang>>
SyntaxNode if one exists. Read moreSource§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
GreenNodeBuilder. Read more