Skip to main content

Scalar

Struct Scalar 

Source
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

Source

pub fn value(&self) -> String

Get the string value of this scalar

Source

pub fn as_string(&self) -> String

Get the string representation of this scalar, properly unquoted and unescaped

Source

pub fn is_quoted(&self) -> bool

Check if this scalar is quoted

Source

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

Source

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.

Source

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.

Source

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
Source

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
Source

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.

Source

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.

Source

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

Try to interpret this scalar as a bool.

Returns None if the scalar is quoted (string type) or is not a recognized boolean value. Recognizes: true, false, True, False, TRUE, FALSE, yes, no, Yes, No, YES, NO, on, off, On, Off, ON, OFF

Source

pub fn is_null(&self) -> bool

Check if this scalar represents a null value.

Returns true if the unquoted value is null, Null, NULL, ~, or empty.

Trait Implementations§

Source§

impl AsYaml for Scalar

Source§

fn as_node(&self) -> Option<&SyntaxNode<Lang>>

Returns a reference to the underlying SyntaxNode if one exists. Read more
Source§

fn kind(&self) -> YamlKind

Returns the kind of YAML value this represents.
Source§

fn build_content( &self, builder: &mut GreenNodeBuilder<'_>, _indent: usize, _flow_context: bool, ) -> bool

Serialize this value into a GreenNodeBuilder. Read more
Source§

fn is_inline(&self) -> bool

Returns whether this value should be rendered on the same line as its key. Read more
Source§

impl AstNode for Scalar

Source§

type Language = Lang

Source§

fn can_cast(kind: SyntaxKind) -> bool

Source§

fn cast(syntax: SyntaxNode<Lang>) -> Option<Self>

Source§

fn syntax(&self) -> &SyntaxNode<Lang>

Source§

fn clone_for_update(&self) -> Self
where Self: Sized,

Source§

fn clone_subtree(&self) -> Self
where Self: Sized,

Source§

impl Clone for Scalar

Source§

fn clone(&self) -> Scalar

Returns a duplicate 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 Debug for Scalar

Source§

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

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

impl Display for Scalar

Source§

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

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

impl From<Scalar> for ScalarValue

Source§

fn from(scalar: Scalar) -> Self

Converts to this type from the input type.
Source§

impl Hash for Scalar

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 PartialEq for Scalar

Source§

fn eq(&self, other: &Scalar) -> 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 TryFrom<&Scalar> for bool

Source§

type Error = ScalarConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(scalar: &Scalar) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Scalar> for f64

Source§

type Error = ScalarConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(scalar: &Scalar) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Scalar> for i64

Source§

type Error = ScalarConversionError

The type returned in the event of a conversion error.
Source§

fn try_from(scalar: &Scalar) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl YamlAccept for Scalar

Source§

fn accept<V: YamlVisitor>(&self, visitor: &mut V)

Accept a visitor for traversal
Source§

impl Eq for Scalar

Source§

impl StructuralPartialEq for Scalar

Auto Trait Implementations§

§

impl Freeze for Scalar

§

impl !RefUnwindSafe for Scalar

§

impl !Send for Scalar

§

impl !Sync for Scalar

§

impl Unpin for Scalar

§

impl UnsafeUnpin for Scalar

§

impl !UnwindSafe for Scalar

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