pub struct ModifierNodeChain { /* private fields */ }Expand description
Chain of modifier nodes attached to a layout node.
The chain tracks ownership of modifier nodes and reuses them across updates when the incoming element list still contains a node of the same type. Removed nodes detach automatically so callers do not need to manually manage their lifetimes.
Implementations§
Source§impl ModifierNodeChain
impl ModifierNodeChain
pub fn new() -> Self
Sourcepub fn detach_nodes(&mut self)
pub fn detach_nodes(&mut self)
Detaches all nodes in the chain.
Sourcepub fn attach_nodes(&mut self, context: &mut dyn ModifierNodeContext)
pub fn attach_nodes(&mut self, context: &mut dyn ModifierNodeContext)
Attaches all nodes in the chain.
Sourcepub fn repair_chain(&mut self)
pub fn repair_chain(&mut self)
Rebuilds the internal chain links (parent/child relationships). This should be called if nodes have been detached but are intended to be reused.
Sourcepub fn update_from_slice(
&mut self,
elements: &[DynModifierElement],
context: &mut dyn ModifierNodeContext,
)
pub fn update_from_slice( &mut self, elements: &[DynModifierElement], context: &mut dyn ModifierNodeContext, )
Reconcile the chain against the provided elements, attaching newly created nodes and detaching nodes that are no longer required.
This method delegates to update_from_ref_iter which handles the
actual reconciliation logic.
Sourcepub fn update_from_ref_iter<'a, I>(
&mut self,
elements: I,
context: &mut dyn ModifierNodeContext,
)where
I: Iterator<Item = &'a DynModifierElement>,
pub fn update_from_ref_iter<'a, I>(
&mut self,
elements: I,
context: &mut dyn ModifierNodeContext,
)where
I: Iterator<Item = &'a DynModifierElement>,
Reconcile the chain against the provided iterator of element references.
This is the preferred method as it avoids requiring a collected slice, enabling zero-allocation traversal of modifier trees.
Sourcepub fn update<I>(&mut self, elements: I, context: &mut dyn ModifierNodeContext)where
I: IntoIterator<Item = DynModifierElement>,
pub fn update<I>(&mut self, elements: I, context: &mut dyn ModifierNodeContext)where
I: IntoIterator<Item = DynModifierElement>,
Convenience wrapper that accepts any iterator of type-erased modifier elements. Elements are collected into a temporary vector before reconciliation.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets all nodes in the chain. This mirrors the behaviour of
Jetpack Compose’s onReset callback.
Sourcepub fn detach_all(&mut self)
pub fn detach_all(&mut self)
Detaches every node in the chain and clears internal storage.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn capabilities(&self) -> NodeCapabilities
pub fn capabilities(&self) -> NodeCapabilities
Returns the aggregated capability mask for the entire chain.
Sourcepub fn has_capability(&self, capability: NodeCapabilities) -> bool
pub fn has_capability(&self, capability: NodeCapabilities) -> bool
Returns true if the chain contains at least one node with the requested capability.
Sourcepub fn head(&self) -> ModifierChainNodeRef<'_>
pub fn head(&self) -> ModifierChainNodeRef<'_>
Returns the sentinel head reference for traversal.
Sourcepub fn tail(&self) -> ModifierChainNodeRef<'_>
pub fn tail(&self) -> ModifierChainNodeRef<'_>
Returns the sentinel tail reference for traversal.
Sourcepub fn head_to_tail(&self) -> ModifierChainIter<'_> ⓘ
pub fn head_to_tail(&self) -> ModifierChainIter<'_> ⓘ
Iterates over the chain from head to tail, skipping sentinels.
Sourcepub fn tail_to_head(&self) -> ModifierChainIter<'_> ⓘ
pub fn tail_to_head(&self) -> ModifierChainIter<'_> ⓘ
Iterates over the chain from tail to head, skipping sentinels.
Sourcepub fn for_each_forward<F>(&self, f: F)where
F: FnMut(ModifierChainNodeRef<'_>),
pub fn for_each_forward<F>(&self, f: F)where
F: FnMut(ModifierChainNodeRef<'_>),
Calls f for every node in insertion order.
Sourcepub fn for_each_forward_matching<F>(&self, mask: NodeCapabilities, f: F)where
F: FnMut(ModifierChainNodeRef<'_>),
pub fn for_each_forward_matching<F>(&self, mask: NodeCapabilities, f: F)where
F: FnMut(ModifierChainNodeRef<'_>),
Calls f for every node containing any capability from mask.
Sourcepub fn for_each_node_with_capability<F>(&self, mask: NodeCapabilities, f: F)
pub fn for_each_node_with_capability<F>(&self, mask: NodeCapabilities, f: F)
Calls f for every node containing any capability from mask, providing the node ref.
Sourcepub fn for_each_backward<F>(&self, f: F)where
F: FnMut(ModifierChainNodeRef<'_>),
pub fn for_each_backward<F>(&self, f: F)where
F: FnMut(ModifierChainNodeRef<'_>),
Calls f for every node in reverse insertion order.
Sourcepub fn for_each_backward_matching<F>(&self, mask: NodeCapabilities, f: F)where
F: FnMut(ModifierChainNodeRef<'_>),
pub fn for_each_backward_matching<F>(&self, mask: NodeCapabilities, f: F)where
F: FnMut(ModifierChainNodeRef<'_>),
Calls f for every node in reverse order that matches mask.
Sourcepub fn node_ref_at(&self, index: usize) -> Option<ModifierChainNodeRef<'_>>
pub fn node_ref_at(&self, index: usize) -> Option<ModifierChainNodeRef<'_>>
Returns a node reference for the entry at index.
Sourcepub fn find_node_ref(
&self,
node: &dyn ModifierNode,
) -> Option<ModifierChainNodeRef<'_>>
pub fn find_node_ref( &self, node: &dyn ModifierNode, ) -> Option<ModifierChainNodeRef<'_>>
Returns the node reference that owns node.
Sourcepub fn node<N: ModifierNode + 'static>(
&self,
index: usize,
) -> Option<Ref<'_, N>>
pub fn node<N: ModifierNode + 'static>( &self, index: usize, ) -> Option<Ref<'_, N>>
Downcasts the node at index to the requested type.
Returns a Ref guard that dereferences to the node type.
Sourcepub fn node_mut<N: ModifierNode + 'static>(
&self,
index: usize,
) -> Option<RefMut<'_, N>>
pub fn node_mut<N: ModifierNode + 'static>( &self, index: usize, ) -> Option<RefMut<'_, N>>
Downcasts the node at index to the requested mutable type.
Returns a RefMut guard that dereferences to the node type.
Sourcepub fn get_node_rc(
&self,
index: usize,
) -> Option<Rc<RefCell<Box<dyn ModifierNode>>>>
pub fn get_node_rc( &self, index: usize, ) -> Option<Rc<RefCell<Box<dyn ModifierNode>>>>
Returns an Rc clone of the node at the given index for shared ownership. This is used by coordinators to hold direct references to nodes.
Sourcepub fn has_nodes_for_invalidation(&self, kind: InvalidationKind) -> bool
pub fn has_nodes_for_invalidation(&self, kind: InvalidationKind) -> bool
Returns true if the chain contains any nodes matching the given invalidation kind.
Sourcepub fn visit_nodes<F>(&self, f: F)
pub fn visit_nodes<F>(&self, f: F)
Visits every node in insertion order together with its capability mask.
Sourcepub fn visit_nodes_mut<F>(&mut self, f: F)
pub fn visit_nodes_mut<F>(&mut self, f: F)
Visits every node mutably in insertion order together with its capability mask.