Switch to using borrows instead of cloning the Rc during iteration.
This commit is contained in:
parent
cfdcb7408a
commit
b6b88a7d78
@ -74,20 +74,19 @@ impl<T: Debug> List<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NodeIter<T> {
|
||||
position: Option<Rc<Node<T>>>,
|
||||
pub struct NodeIter<'a, T> {
|
||||
position: &'a Option<Rc<Node<T>>>,
|
||||
}
|
||||
|
||||
impl<T> Iterator for NodeIter<T> {
|
||||
// TODO: This would be a lot better if it returned borrows instead of clones of Rc
|
||||
type Item = Rc<Node<T>>;
|
||||
impl<'a, T> Iterator for NodeIter<'a, T> {
|
||||
type Item = &'a Rc<Node<T>>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let (return_value, next_position) = match &self.position {
|
||||
None => return None,
|
||||
Some(rc_node) => {
|
||||
let next_position = rc_node.parent.clone();
|
||||
let return_value = rc_node.clone();
|
||||
let next_position = &rc_node.parent;
|
||||
let return_value = rc_node;
|
||||
(return_value, next_position)
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user