Skip to main content

GreenNode

Struct GreenNode 

Source
pub struct GreenNode<'a, L: Language> {
    pub kind: L::ElementType,
    pub children: &'a [GreenTree<'a, L>],
    pub byte_length: u32,
}
Expand description

A green node that contains child elements.

Green nodes are allocated in a SyntaxArena and hold a slice reference to their children. They are POD (Plain Old Data) and strictly immutable.

Unlike red nodes, green nodes do not know their absolute position in the source code, which makes them highly reusable for incremental parsing.

Fields§

§kind: L::ElementType

The element type (kind) of this node.

§children: &'a [GreenTree<'a, L>]

The children of this node, which can be other nodes or leaf tokens.

§byte_length: u32

The total text length of this node (sum of children’s lengths) in bytes.

Implementations§

Source§

impl<'a, L: Language> GreenNode<'a, L>

Source

pub fn new(kind: L::ElementType, children: &'a [GreenTree<'a, L>]) -> Self

Creates a new green node from child elements.

This function assumes the children slice is already allocated in the arena. It automatically calculates the total text_len by summing child lengths.

§Arguments
  • kind - The node type.
  • children - The slice of child elements.
Source

pub fn kind(&self) -> L::ElementType

Returns the kind of this node.

Source

pub fn text_len(&self) -> u32

Returns the total text length of this node in bytes.

Source

pub fn children(&self) -> &'a [GreenTree<'a, L>]

Returns the children of this node.

Source

pub fn child_at(&self, index: usize) -> Option<&'a GreenTree<'a, L>>

Returns a specific child at index.

Returns None if the index is out of bounds.

Source

pub fn has_children(&self) -> bool

Checks if this node has any children.

Source

pub fn children_count(&self) -> usize

Returns the number of children in this node.

Trait Implementations§

Source§

impl<'a, L: Language> Clone for GreenNode<'a, L>

Source§

fn clone(&self) -> Self

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<'a, L: Language> Debug for GreenNode<'a, L>

Source§

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

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

impl<'a, L: Language> Hash for GreenNode<'a, L>

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<'a, L: Language> PartialEq for GreenNode<'a, L>

Source§

fn eq(&self, other: &Self) -> 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<'a, L: Language> Eq for GreenNode<'a, L>

Auto Trait Implementations§

§

impl<'a, L> Freeze for GreenNode<'a, L>
where <L as Language>::ElementType: Freeze,

§

impl<'a, L> RefUnwindSafe for GreenNode<'a, L>

§

impl<'a, L> Send for GreenNode<'a, L>

§

impl<'a, L> Sync for GreenNode<'a, L>

§

impl<'a, L> Unpin for GreenNode<'a, L>
where <L as Language>::ElementType: Unpin,

§

impl<'a, L> UnsafeUnpin for GreenNode<'a, L>

§

impl<'a, L> UnwindSafe for GreenNode<'a, L>

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.