Skip to main content

NodeResource

Struct NodeResource 

Source
pub struct NodeResource { /* private fields */ }
Expand description

Backing for a node WIT resource: a path of Node::child indices from the tree root (empty = root), re-resolved against snapshot on each call.

§Why the two caches (OA.0a)

The path is the identity, and re-resolving it walks from the root — the last step, Node::child(i), is O(i). So every accessor on the i-th child cost O(i), and named_child additionally rescanned the child list from zero on each call. Iterating one node’s k children was therefore O(k²), which made a guest tree walk quadratic in file size: a 34 KB org file took 29 seconds to scan, and the agenda it fed never arrived.

Both caches close that without changing the WIT or the guest:

  • meta — this node’s own kind / range / flags, resolved at most once.
  • children — one TreeCursor pass over the children, which is O(k) and answers named_child_count, named_child and child_by_field in O(1) thereafter. Each entry carries enough to seed the child’s own meta, so walking into a child resolves nothing at all.

A snapshot is immutable, so a cached answer cannot go stale.

Implementations§

Source§

impl NodeResource

Source

pub fn path(&self) -> &[u32]

The node’s root-relative child-index path — read by the host reset binding to reposition a cursor onto this node.

Source

pub fn kind(&self) -> String

The node’s grammar kind (empty string if the path can’t resolve — never panics; an immutable snapshot always resolves).

Source

pub fn is_named(&self) -> bool

Source

pub fn is_error(&self) -> bool

Source

pub fn byte_range(&self) -> NativeRange

The node’s [start, end) span as byte-columns per line (matching the native structural objects’ ProtoRange). A zero range if unresolved.

Source

pub fn parent(&self) -> Option<NodeResource>

The parent node, or None at the root.

Source

pub fn named_child_count(&self) -> u32

Source

pub fn named_child(&self, index: u32) -> Option<NodeResource>

The index-th NAMED child, mapped to its child (all-children) index so the path stays in one indexing scheme.

Source

pub fn child_by_field(&self, name: &str) -> Option<NodeResource>

The child under grammar field name (e.g. "body"), or None.

Source

pub fn next_named_sibling(&self) -> Option<NodeResource>

Source

pub fn prev_named_sibling(&self) -> Option<NodeResource>

Source

pub fn walk(&self) -> CursorResource

TS.2: a walk cursor positioned at this node.

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Pointer = u32

§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more