RedNode

Struct RedNode 

Source
pub struct RedNode<K: Copy> {
    pub green: Arc<GreenNode<K>>,
    pub offset: usize,
}
Expand description

A red node that wraps a green node with absolute offset information.

Red nodes represent kind tree nodes with computed absolute positions, making them suitable for incremental parsing and position-based operations.

Fields§

§green: Arc<GreenNode<K>>

The underlying green node that contains the structural information

§offset: usize

The absolute byte offset of this node in the source text

Implementations§

Source§

impl<K: Copy> RedNode<K>

Source

pub fn new(green: Arc<GreenNode<K>>, offset: usize) -> Self

Creates a new red node from a green node and offset.

§Arguments
  • green - The green node containing structural information
  • offset - The absolute byte offset in the source text
§Returns

A new RedNode with the given green node and offset

Source

pub fn span(&self) -> Range<usize>

Returns the absolute byte span of this red node.

The span is computed from the node’s offset and the length of the underlying green node.

§Returns

A Range<usize> representing the absolute byte positions

Source

pub fn child(&self, idx: usize) -> Option<RedTree<K>>

Gets the child element at the specified index.

§Arguments
  • idx - The index of the child element to retrieve
§Returns

An Option<RedTree<K>> containing the child element if it exists, or None if the index is out of bounds

Source

pub fn children(&self) -> RedChildren<'_, K>

Returns an iterator over all child elements.

§Returns

A RedChildren<K> iterator that yields all child elements in order

Source§

impl<K: Copy> RedNode<K>

Source

pub fn child_index_at_offset(&self, offset: usize) -> Option<usize>

Finds the index of the child element that contains the given absolute offset.

This method is essential for incremental parsing, allowing efficient location of affected regions when source text changes.

§Arguments
  • offset - The absolute byte offset to search for
§Returns

An Option<usize> containing the child index if found, or None if the offset is outside this node’s span

Source

pub fn offset_of_child(&self, idx: usize) -> Option<usize>

Gets the absolute starting offset of the child element at the given index.

§Arguments
  • idx - The index of the child element
§Returns

An Option<usize> containing the absolute offset if the index is valid

Source

pub fn overlapping_indices(&self, span: Range<usize>) -> Vec<usize>

Collects indices of child elements that overlap with the given span.

This method is crucial for incremental parsing, identifying which child elements are affected by a text change.

§Arguments
  • span - The byte range to check for overlaps
§Returns

A Vec<usize> containing indices of all overlapping child elements

Trait Implementations§

Source§

impl<K: Clone + Copy> Clone for RedNode<K>

Source§

fn clone(&self) -> RedNode<K>

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<K: Debug + Copy> Debug for RedNode<K>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K> Freeze for RedNode<K>

§

impl<K> RefUnwindSafe for RedNode<K>
where K: RefUnwindSafe,

§

impl<K> Send for RedNode<K>
where K: Sync + Send,

§

impl<K> Sync for RedNode<K>
where K: Sync + Send,

§

impl<K> Unpin for RedNode<K>
where K: Unpin,

§

impl<K> UnwindSafe for RedNode<K>
where K: RefUnwindSafe,

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<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, 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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,