pub struct Sequence(/* private fields */);Expand description
A YAML sequence (list)
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 Sequence
impl Sequence
Sourcepub fn values(&self) -> impl Iterator<Item = YamlNode> + '_
pub fn values(&self) -> impl Iterator<Item = YamlNode> + '_
Iterate over items in this sequence as YamlNodes.
Items that cannot be wrapped as a YamlNode are silently skipped.
Source§impl Sequence
impl Sequence
Sourcepub fn push(&self, value: impl AsYaml)
pub fn push(&self, value: impl AsYaml)
Add an item to the end of the sequence.
Mutates in place despite &self (see crate docs on interior mutability).
Sourcepub fn insert(&self, index: usize, value: impl AsYaml)
pub fn insert(&self, index: usize, value: impl AsYaml)
Insert an item at a specific position.
If index is out of bounds, the item is appended at the end.
This method always succeeds; it never returns an error.
Mutates in place despite &self (see crate docs on interior mutability).
Sourcepub fn set(&self, index: usize, value: impl AsYaml) -> bool
pub fn set(&self, index: usize, value: impl AsYaml) -> bool
Replace the item at index with a new value.
Returns true if the index was in bounds and the item was replaced,
false if index >= len().
Mutates in place despite &self (see crate docs on interior mutability).
Sourcepub fn remove(&self, index: usize) -> Option<YamlNode>
pub fn remove(&self, index: usize) -> Option<YamlNode>
Remove the item at index, returning its value.
Returns Some(value) if the index was in bounds, None otherwise.
Mutates in place despite &self (see crate docs on interior mutability).
Sourcepub fn is_flow_style(&self) -> bool
pub fn is_flow_style(&self) -> bool
Check if this sequence is in flow style [item1, item2]
Sourcepub fn pop(&self) -> Option<YamlNode>
pub fn pop(&self) -> Option<YamlNode>
Remove and return the last item in this sequence.
Returns None if the sequence is empty.
Mutates in place despite &self (see crate docs on interior mutability).
Sourcepub fn clear(&self)
pub fn clear(&self)
Remove all items from this sequence.
Mutates in place despite &self (see crate docs on interior mutability).
Sourcepub fn byte_range(&self) -> TextPosition
pub fn byte_range(&self) -> TextPosition
Get the byte offset range of this sequence 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 sequence 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 sequence 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
Trait Implementations§
Source§impl AsYaml for Sequence
impl AsYaml for Sequence
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