Skip to main content

ModifierNodeChain

Struct ModifierNodeChain 

Source
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

Source

pub fn new() -> Self

Source

pub fn detach_nodes(&mut self)

Detaches all nodes in the chain.

Source

pub fn attach_nodes(&mut self, context: &mut dyn ModifierNodeContext)

Attaches all nodes in the chain.

Source

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.

Source

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.

Source

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.

Source

pub fn update<I>(&mut self, elements: I, context: &mut dyn ModifierNodeContext)

Convenience wrapper that accepts any iterator of type-erased modifier elements. Elements are collected into a temporary vector before reconciliation.

Source

pub fn reset(&mut self)

Resets all nodes in the chain. This mirrors the behaviour of Jetpack Compose’s onReset callback.

Source

pub fn detach_all(&mut self)

Detaches every node in the chain and clears internal storage.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn capabilities(&self) -> NodeCapabilities

Returns the aggregated capability mask for the entire chain.

Source

pub fn has_capability(&self, capability: NodeCapabilities) -> bool

Returns true if the chain contains at least one node with the requested capability.

Source

pub fn head(&self) -> ModifierChainNodeRef<'_>

Returns the sentinel head reference for traversal.

Source

pub fn tail(&self) -> ModifierChainNodeRef<'_>

Returns the sentinel tail reference for traversal.

Source

pub fn head_to_tail(&self) -> ModifierChainIter<'_>

Iterates over the chain from head to tail, skipping sentinels.

Source

pub fn tail_to_head(&self) -> ModifierChainIter<'_>

Iterates over the chain from tail to head, skipping sentinels.

Source

pub fn for_each_forward<F>(&self, f: F)

Calls f for every node in insertion order.

Source

pub fn for_each_forward_matching<F>(&self, mask: NodeCapabilities, f: F)

Calls f for every node containing any capability from mask.

Source

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.

Source

pub fn for_each_backward<F>(&self, f: F)

Calls f for every node in reverse insertion order.

Source

pub fn for_each_backward_matching<F>(&self, mask: NodeCapabilities, f: F)

Calls f for every node in reverse order that matches mask.

Source

pub fn node_ref_at(&self, index: usize) -> Option<ModifierChainNodeRef<'_>>

Returns a node reference for the entry at index.

Source

pub fn find_node_ref( &self, node: &dyn ModifierNode, ) -> Option<ModifierChainNodeRef<'_>>

Returns the node reference that owns node.

Source

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.

Source

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.

Source

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.

Source

pub fn has_nodes_for_invalidation(&self, kind: InvalidationKind) -> bool

Returns true if the chain contains any nodes matching the given invalidation kind.

Source

pub fn visit_nodes<F>(&self, f: F)

Visits every node in insertion order together with its capability mask.

Source

pub fn visit_nodes_mut<F>(&mut self, f: F)
where F: FnMut(&mut dyn ModifierNode, NodeCapabilities),

Visits every node mutably in insertion order together with its capability mask.

Trait Implementations§

Source§

impl Default for ModifierNodeChain

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.

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, 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.