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— oneTreeCursorpass over the children, which is O(k) and answersnamed_child_count,named_childandchild_by_fieldin O(1) thereafter. Each entry carries enough to seed the child’s ownmeta, so walking into a child resolves nothing at all.
A snapshot is immutable, so a cached answer cannot go stale.
Implementations§
Source§impl NodeResource
impl NodeResource
Sourcepub fn path(&self) -> &[u32]
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.
Sourcepub fn kind(&self) -> String
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).
pub fn is_named(&self) -> bool
pub fn is_error(&self) -> bool
Sourcepub fn byte_range(&self) -> NativeRange
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.
Sourcepub fn parent(&self) -> Option<NodeResource>
pub fn parent(&self) -> Option<NodeResource>
The parent node, or None at the root.
pub fn named_child_count(&self) -> u32
Sourcepub fn named_child(&self, index: u32) -> Option<NodeResource>
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.
Sourcepub fn child_by_field(&self, name: &str) -> Option<NodeResource>
pub fn child_by_field(&self, name: &str) -> Option<NodeResource>
The child under grammar field name (e.g. "body"), or None.
pub fn next_named_sibling(&self) -> Option<NodeResource>
pub fn prev_named_sibling(&self) -> Option<NodeResource>
Sourcepub fn walk(&self) -> CursorResource
pub fn walk(&self) -> CursorResource
TS.2: a walk cursor positioned at this node.
Auto Trait Implementations§
impl !Freeze for NodeResource
impl RefUnwindSafe for NodeResource
impl Send for NodeResource
impl Sync for NodeResource
impl Unpin for NodeResource
impl UnsafeUnpin for NodeResource
impl UnwindSafe for NodeResource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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