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> {
|
pub struct NodeIter<'a, T> {
|
||||||
position: Option<Rc<Node<T>>>,
|
position: &'a Option<Rc<Node<T>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Iterator for NodeIter<T> {
|
impl<'a, T> Iterator for NodeIter<'a, T> {
|
||||||
// TODO: This would be a lot better if it returned borrows instead of clones of Rc
|
type Item = &'a Rc<Node<T>>;
|
||||||
type Item = Rc<Node<T>>;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let (return_value, next_position) = match &self.position {
|
let (return_value, next_position) = match &self.position {
|
||||||
None => return None,
|
None => return None,
|
||||||
Some(rc_node) => {
|
Some(rc_node) => {
|
||||||
let next_position = rc_node.parent.clone();
|
let next_position = &rc_node.parent;
|
||||||
let return_value = rc_node.clone();
|
let return_value = rc_node;
|
||||||
(return_value, next_position)
|
(return_value, next_position)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user