Skip to content

Commit

Permalink
fix cargo warning about dead code
Browse files Browse the repository at this point in the history
this caused a small cascade of changes related to generic types and
lifetime annotations.
  • Loading branch information
iwburns committed Feb 9, 2019
1 parent 93c2f19 commit 482c00a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/iterators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,25 +268,23 @@ impl<'a, T> Iterator for PostOrderTraversal<'a, T> {
/// Iterates over all of the `NodeId`s in the sub-tree of a given `NodeId` in the `Tree`. Each call to
/// `next` will return the next `NodeId` in Post-Order Traversal order.
///
pub struct PostOrderTraversalIds<'a, T: 'a> {
tree: &'a Tree<T>,
pub struct PostOrderTraversalIds {
ids: IntoIter<NodeId>,
}

impl<'a, T> PostOrderTraversalIds<'a, T> {
pub(crate) fn new(tree: &'a Tree<T>, node_id: NodeId) -> PostOrderTraversalIds<T> {
impl PostOrderTraversalIds {
pub(crate) fn new<T>(tree: &Tree<T>, node_id: NodeId) -> PostOrderTraversalIds {
// over allocating, but all at once instead of re-sizing and re-allocating as we go
let mut ids = Vec::with_capacity(tree.capacity());

PostOrderTraversalIds::process_nodes(node_id, tree, &mut ids);

PostOrderTraversalIds {
tree: tree,
ids: ids.into_iter(),
}
}

fn process_nodes(starting_id: NodeId, tree: &Tree<T>, ids: &mut Vec<NodeId>) {
fn process_nodes<T>(starting_id: NodeId, tree: &Tree<T>, ids: &mut Vec<NodeId>) {
let node = tree.get(&starting_id).unwrap();

for child_id in node.children() {
Expand All @@ -297,7 +295,7 @@ impl<'a, T> PostOrderTraversalIds<'a, T> {
}
}

impl<'a, T> Iterator for PostOrderTraversalIds<'a, T> {
impl Iterator for PostOrderTraversalIds {
type Item = NodeId;

fn next(&mut self) -> Option<NodeId> {
Expand Down
2 changes: 1 addition & 1 deletion src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ impl<T> Tree<T> {
pub fn traverse_post_order_ids(
&self,
node_id: &NodeId,
) -> Result<PostOrderTraversalIds<T>, NodeIdError> {
) -> Result<PostOrderTraversalIds, NodeIdError> {
let (is_valid, error) = self.is_valid_node_id(node_id);
if !is_valid {
return Err(error.expect(
Expand Down

0 comments on commit 482c00a

Please sign in to comment.