Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand traverse and descendants documentation: Issue #369 #375

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/arena_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,36 @@ impl<'a, T> Node<'a, T> {
ReverseChildren(self.last_child.get())
}

/// Return an iterator of references to this node and its descendants, in tree order.
/// 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.
///
/// *Similar Functions:* Use `traverse()` or `reverse_traverse` if you need
/// references to the `NodeEdge` structs associated with each `Node`
pub fn descendants(&'a self) -> Descendants<'a, T> {
Descendants(self.traverse())
}

/// Return an iterator of references to this node and its descendants, in tree order.
/// Return an iterator of references to `NodeEdge` enums for each `Node` and its descendants,
/// in tree order.
///
/// `NodeEdge` enums represent the `Start` or `End` of each node.
///
/// *Similar Functions:* Use `descendants()` if you don't need `Start` and `End`.
pub fn traverse(&'a self) -> Traverse<'a, T> {
Traverse {
root: self,
next: Some(NodeEdge::Start(self)),
}
}

/// Return an iterator of references to this node and its descendants, in tree order.
/// Return an iterator of references to `NodeEdge` enums for each `Node` and its descendants,
/// in *reverse* order.
///
/// `NodeEdge` enums represent the `Start` or `End` of each node.
///
/// *Similar Functions:* Use `descendants()` if you don't need `Start` and `End`.
pub fn reverse_traverse(&'a self) -> ReverseTraverse<'a, T> {
ReverseTraverse {
root: self,
Expand Down
Loading