Skip to main content

Node

Trait Node 

Source
pub trait Node: Any {
Show 32 methods // Provided methods fn mount(&mut self) { ... } fn unmount(&mut self) { ... } fn insert_child(&mut self, _child: NodeId) -> bool { ... } fn remove_child(&mut self, _child: NodeId) -> bool { ... } fn move_child(&mut self, _from: usize, _to: usize) { ... } fn update_children(&mut self, _children: &[NodeId]) { ... } fn collect_children_into(&self, out: &mut SmallVec<[NodeId; 8]>) { ... } fn collect_owned_children_into(&self, out: &mut SmallVec<[NodeId; 8]>) { ... } fn owned_child_index(&self, child: NodeId) -> Option<usize> { ... } fn set_node_id(&mut self, _id: NodeId) { ... } fn on_attached_to_parent(&mut self, _parent: NodeId) { ... } fn on_removed_from_parent(&mut self) { ... } fn parent(&self) -> Option<NodeId> { ... } fn mark_needs_layout(&self) { ... } fn needs_layout(&self) -> bool { ... } fn mark_needs_measure(&self) { ... } fn needs_measure(&self) -> bool { ... } fn mark_descendant_needs_layout(&self, measure: bool) { ... } fn descendant_needs_layout(&self) -> bool { ... } fn descendant_needs_measure(&self) -> bool { ... } fn layout_dirty(&self) -> bool { ... } fn is_virtual(&self) -> bool { ... } fn mark_needs_semantics(&self) { ... } fn mark_descendant_needs_semantics(&self) { ... } fn needs_semantics(&self) -> bool { ... } fn set_parent_for_bubbling(&mut self, parent: NodeId) { ... } fn recycle_key(&self) -> Option<TypeId> { ... } fn recycle_pool_limit(&self) -> Option<usize> { ... } fn prepare_for_recycle(&mut self) { ... } fn rehouse_for_recycle(&self) -> Option<Box<dyn Node>> { ... } fn rehouse_for_live_compaction(&mut self) -> Option<Box<dyn Node>> { ... } fn debug_heap_bytes(&self) -> usize { ... }
}
Expand description

A node of the tree that a composition builds. An applier stores the nodes by id. Every method has a default, so a simple node implements none of them.

Provided Methods§

Source

fn mount(&mut self)

Called once the node has its id, when the composition applies the node’s creation.

Source

fn unmount(&mut self)

Called just before the node is removed from the applier.

Source

fn insert_child(&mut self, _child: NodeId) -> bool

Adds child to this node’s child list, returning whether the list actually changed. A node that already holds the child returns false: callers record a structural change from this answer, and a structural change re-lowers the whole subtree, so claiming one for a no-op costs a full rebuild per call.

Source

fn remove_child(&mut self, _child: NodeId) -> bool

Removes child from this node’s child list, returning whether the list actually changed. Only this node can answer that: a caller inspecting the child’s parent pointer gets it wrong when the child was reparented while still listed here.

Source

fn move_child(&mut self, _from: usize, _to: usize)

Moves the child at the first index to the second index in the child list.

Source

fn update_children(&mut self, _children: &[NodeId])

Replaces the child list with children, in order.

Source

fn collect_children_into(&self, out: &mut SmallVec<[NodeId; 8]>)

Copies child IDs into the provided scratch buffer without allocating a fresh container for every traversal. A node without children leaves the buffer empty.

Source

fn collect_owned_children_into(&self, out: &mut SmallVec<[NodeId; 8]>)

Copies the ids of the children this node owns, in order, into out. A node whose collect_children_into leaves some children out overrides this to list them all. The default calls collect_children_into.

Source

fn owned_child_index(&self, child: NodeId) -> Option<usize>

Finds a child in the order returned by Node::collect_owned_children_into. Nodes with slice-backed child storage should override this to avoid materializing the whole list for a single lookup.

use cranpose_core::{Node, NodeId};

fn child_is_first(parent: &dyn Node, child: NodeId) -> bool {
    parent.owned_child_index(child) == Some(0)
}
Source

fn set_node_id(&mut self, _id: NodeId)

Called after the node is created to record its own ID. Useful for nodes that need to store their ID for later operations.

Source

fn on_attached_to_parent(&mut self, _parent: NodeId)

Called when this node is attached to a parent. Nodes with parent tracking should set their parent reference here.

Source

fn on_removed_from_parent(&mut self)

Called when this node is removed from its parent. Nodes with parent tracking should clear their parent reference here.

Source

fn parent(&self) -> Option<NodeId>

Get this node’s parent ID (for nodes that track parents). Returns None if node has no parent or doesn’t track parents.

Source

fn mark_needs_layout(&self)

Mark this node as needing layout (for nodes with dirty flags). Called during bubbling to propagate dirtiness up the tree.

Source

fn needs_layout(&self) -> bool

Check if this node needs layout (for nodes with dirty flags).

Source

fn mark_needs_measure(&self)

Mark this node as needing measure (size may have changed). Called during bubbling when children are added/removed.

Source

fn needs_measure(&self) -> bool

Check if this node needs measure (for nodes with dirty flags).

Source

fn mark_descendant_needs_layout(&self, measure: bool)

Mark that a node below this one needs layout, or measure when measure is set: a layout pass has to visit this node to reach it, while this node’s own measurement may still hold. A node that does not track the difference marks itself dirty.

Source

fn descendant_needs_layout(&self) -> bool

Check if a node below this one needs layout or measure.

Source

fn descendant_needs_measure(&self) -> bool

Check if a node below this one needs measure.

Source

fn layout_dirty(&self) -> bool

Check if a layout pass has to visit this node: the node or a node below it needs layout or measure.

Source

fn is_virtual(&self) -> bool

Whether the node lays out nothing itself and its parent lays out its children, so a change of its own is a change of its parent’s.

Source

fn mark_needs_semantics(&self)

Mark this node as needing semantics recomputation.

Source

fn mark_descendant_needs_semantics(&self)

Mark that the semantics tree has to read this node again while its own semantics are unchanged: a node below it changed its semantics, or its own placement or children changed.

Source

fn needs_semantics(&self) -> bool

Check if this node or a node below it needs semantics recomputation.

Source

fn set_parent_for_bubbling(&mut self, parent: NodeId)

Set parent reference for dirty flag bubbling ONLY. This is a minimal version of on_attached_to_parent that doesn’t trigger registry updates or other side effects. Used during measurement when we need to establish parent connections for bubble_measure_dirty without causing the full attachment lifecycle.

An existing parent is preserved until the structural attach operation removes the node from its previous container.

Source

fn recycle_key(&self) -> Option<TypeId>

Returns a recycle pool key when this node supports shell reuse.

Source

fn recycle_pool_limit(&self) -> Option<usize>

Bounds how many recyclable shells of this node type should be retained.

Source

fn prepare_for_recycle(&mut self)

Clears live attachments before the node shell enters a recycle pool.

Source

fn rehouse_for_recycle(&self) -> Option<Box<dyn Node>>

Optionally provides a compact replacement box for this recycled shell.

Returning Some lets nodes move pooled survivors onto fresh compact storage so the recycle pool does not pin large spike-era allocations.

Source

fn rehouse_for_live_compaction(&mut self) -> Option<Box<dyn Node>>

Optionally moves a live node onto a fresh box during applier compaction.

This is used after large-majority teardowns where a small surviving live tree can otherwise pin allocator pages from a much larger spike-era node population. Implementations must preserve the node’s live state.

Source

fn debug_heap_bytes(&self) -> usize

Returns the node-owned heap retained beyond the node’s own box allocation.

Implementations§

Source§

impl dyn Node

Source

pub fn as_any_mut(&mut self) -> &mut dyn Any

Returns the node as Any, for downcasting to its concrete type.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§