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 ancestors<'a>(
self,
node_hierarchy: &'a NodeHierarchyRef<'a>,
) -> Ancestors<'a> ⓘ
pub const fn ancestors<'a>( self, node_hierarchy: &'a NodeHierarchyRef<'a>, ) -> Ancestors<'a> ⓘ
Return an iterator of references to this node and its ancestors.
Call .next().unwrap() once on the iterator to skip the node itself.
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 const fn following_siblings<'a>(
self,
node_hierarchy: &'a NodeHierarchyRef<'a>,
) -> FollowingSiblings<'a> ⓘ
pub const fn following_siblings<'a>( self, node_hierarchy: &'a NodeHierarchyRef<'a>, ) -> FollowingSiblings<'a> ⓘ
Return an iterator of references to this node and the siblings after 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.
Sourcepub fn reverse_children<'a>(
self,
node_hierarchy: &'a NodeHierarchyRef<'a>,
) -> ReverseChildren<'a> ⓘ
pub fn reverse_children<'a>( self, node_hierarchy: &'a NodeHierarchyRef<'a>, ) -> ReverseChildren<'a> ⓘ
Return an iterator of references to this node’s children, in reverse order.
Sourcepub const fn descendants<'a>(
self,
node_hierarchy: &'a NodeHierarchyRef<'a>,
) -> Descendants<'a> ⓘ
pub const fn descendants<'a>( self, node_hierarchy: &'a NodeHierarchyRef<'a>, ) -> Descendants<'a> ⓘ
Return an iterator of references to this node and its descendants, in tree order.
Parent nodes appear before the descendants.
Call .next().unwrap() once on the iterator to skip the node itself.
Sourcepub const fn traverse<'a>(
self,
node_hierarchy: &'a NodeHierarchyRef<'a>,
) -> Traverse<'a> ⓘ
pub const fn traverse<'a>( self, node_hierarchy: &'a NodeHierarchyRef<'a>, ) -> Traverse<'a> ⓘ
Return an iterator of references to this node and its descendants, in tree order.
Sourcepub const fn reverse_traverse<'a>(
self,
node_hierarchy: &'a NodeHierarchyRef<'a>,
) -> ReverseTraverse<'a> ⓘ
pub const fn reverse_traverse<'a>( self, node_hierarchy: &'a NodeHierarchyRef<'a>, ) -> ReverseTraverse<'a> ⓘ
Return an iterator of references to this node and its descendants, in tree order.
Source§impl NodeId
impl NodeId
pub fn get_nearest_matching_parent<'a, F>( self, node_hierarchy: &'a NodeDataContainerRef<'a, NodeHierarchyItem>, predicate: F, ) -> Option<NodeId>
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 moreSource§impl<'a, T> Index<NodeId> for NodeDataContainerRef<'a, T>
impl<'a, T> Index<NodeId> for NodeDataContainerRef<'a, T>
Source§impl<'a, T> Index<NodeId> for NodeDataContainerRefMut<'a, T>
impl<'a, T> Index<NodeId> for NodeDataContainerRefMut<'a, T>
Source§impl<'a> Index<NodeId> for NodeHierarchyRef<'a>
impl<'a> Index<NodeId> for NodeHierarchyRef<'a>
Source§impl<'a> Index<NodeId> for NodeHierarchyRefMut<'a>
impl<'a> Index<NodeId> for NodeHierarchyRefMut<'a>
Source§impl<'a, T> IndexMut<NodeId> for NodeDataContainerRefMut<'a, T>
impl<'a, T> IndexMut<NodeId> for NodeDataContainerRefMut<'a, T>
Source§impl<'a> IndexMut<NodeId> for NodeHierarchyRefMut<'a>
impl<'a> IndexMut<NodeId> for NodeHierarchyRefMut<'a>
Source§impl Ord for NodeId
impl Ord for NodeId
Source§impl PartialOrd for NodeId
impl PartialOrd for NodeId
impl Copy for NodeId
impl Eq for NodeId
impl StructuralPartialEq for NodeId
Auto Trait Implementations§
impl Freeze for NodeId
impl RefUnwindSafe for NodeId
impl Send for NodeId
impl Sync for NodeId
impl Unpin for NodeId
impl UnwindSafe for NodeId
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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