pub struct NodeId { /* private fields */ }Expand description
A type-safe identifier for a node within a DOM tree.
NodeId is FFI-safe (#[repr(C)]) and stores a zero-based index internally.
Use NodeId::index() to get the array index for direct node access.
§Zero-based indexing
NodeId::new(0)→ first node (index 0)NodeId::new(5)→ sixth node (index 5)- Use
node_id.index()to get the array index
§FFI Encoding (for Option<NodeId>)
When storing Option<NodeId> in FFI structs (like NodeHierarchyItem),
we use a 1-based encoding to represent None:
0meansNone(no node)n > 0meansSome(NodeId(n - 1))
Use NodeId::from_usize to decode and NodeId::into_raw to encode.
See also: crate::styled_dom::NodeHierarchyItemId for the FFI wrapper type.
§Warning
Never manually construct raw usize values for node hierarchy fields!
Always use the provided from_usize/into_raw functions to avoid
off-by-one errors that can cause index-out-of-bounds panics.
Implementations§
Source§impl NodeId
impl NodeId
Sourcepub const fn from_usize(value: usize) -> Option<Self>
pub const fn from_usize(value: usize) -> Option<Self>
Decodes a raw usize to Option<NodeId> using 1-based encoding.
This is the inverse of [NodeId::into_usize].
0→None(no node)n > 0→Some(NodeId(n - 1))
§Warning
This function is for decoding values stored in FFI structs like
NodeHierarchyItem. Do not use raw usize values directly - always
decode them first!
Sourcepub const fn into_raw(val: &Option<Self>) -> usize
pub const fn into_raw(val: &Option<Self>) -> usize
Encodes Option<NodeId> to a raw usize for storage in FFI structs.
None→0Some(NodeId(n))→n + 1
The returned value uses 1-based encoding! A value of 0 means “no node”,
NOT “node at index 0”. Use NodeId::from_usize to decode.
Source§impl NodeId
impl NodeId
Sourcepub const fn preceding_siblings<'a>(
self,
node_hierarchy: &'a NodeHierarchyRef<'a>,
) -> PrecedingSiblings<'a> ⓘ
pub const fn preceding_siblings<'a>( self, node_hierarchy: &'a NodeHierarchyRef<'a>, ) -> PrecedingSiblings<'a> ⓘ
Return an iterator of references to this node and the siblings before it.
Call .next().unwrap() once on the iterator to skip the node itself.
Sourcepub fn children<'a>(
self,
node_hierarchy: &'a NodeHierarchyRef<'a>,
) -> Children<'a> ⓘ
pub fn children<'a>( self, node_hierarchy: &'a NodeHierarchyRef<'a>, ) -> Children<'a> ⓘ
Return an iterator of references to this node’s children.
Source§impl NodeId
impl NodeId
Sourcepub fn get_nearest_matching_parent<'a, F>(
self,
node_hierarchy: &'a NodeDataContainerRef<'a, NodeHierarchyItem>,
predicate: F,
) -> Option<NodeId>
pub fn get_nearest_matching_parent<'a, F>( self, node_hierarchy: &'a NodeDataContainerRef<'a, NodeHierarchyItem>, predicate: F, ) -> Option<NodeId>
Traverse up through the hierarchy until a node matching the predicate is found.
Necessary to resolve the last positioned (= relative) element of an absolute node.
Sourcepub fn az_children_collect<'a>(
self,
node_hierarchy: &'a NodeDataContainerRef<'a, NodeHierarchyItem>,
) -> Vec<NodeId>
pub fn az_children_collect<'a>( self, node_hierarchy: &'a NodeDataContainerRef<'a, NodeHierarchyItem>, ) -> Vec<NodeId>
Return the children of this node (necessary for parallel iteration over children)
Sourcepub fn az_children<'a>(
self,
node_hierarchy: &'a NodeDataContainerRef<'a, NodeHierarchyItem>,
) -> AzChildren<'a> ⓘ
pub fn az_children<'a>( self, node_hierarchy: &'a NodeDataContainerRef<'a, NodeHierarchyItem>, ) -> AzChildren<'a> ⓘ
Return an iterator of references to this node’s children.
Sourcepub fn az_reverse_children<'a>(
self,
node_hierarchy: &'a NodeDataContainerRef<'a, NodeHierarchyItem>,
) -> AzReverseChildren<'a> ⓘ
pub fn az_reverse_children<'a>( self, node_hierarchy: &'a NodeDataContainerRef<'a, NodeHierarchyItem>, ) -> AzReverseChildren<'a> ⓘ
Return an iterator of references to this node’s children.
Trait Implementations§
Source§impl AddAssign<usize> for NodeId
impl AddAssign<usize> for NodeId
Source§fn add_assign(&mut self, other: usize)
fn add_assign(&mut self, other: usize)
+= operation. Read more