Skip to content
Snippets Groups Projects
Commit 4d045fcf authored by Ralf Jung's avatar Ralf Jung
Browse files

dlist_arc: cursor support

parent e92d0828
Branches
Tags
No related merge requests found
...@@ -116,6 +116,16 @@ impl<'id, T> Node<'id, T> { ...@@ -116,6 +116,16 @@ impl<'id, T> Node<'id, T> {
cur = node.next.as_deref(); cur = node.next.as_deref();
} }
} }
pub fn cursor_mut<'curs>(
node: NodePtr<'id, T>,
token: &'curs mut GhostToken<'id>,
) -> CursorMut<'id, 'curs, T> {
CursorMut {
cur: Some(node),
token,
}
}
} }
/// An immutable iterator. /// An immutable iterator.
...@@ -142,3 +152,28 @@ where ...@@ -142,3 +152,28 @@ where
} }
} }
} }
pub struct CursorMut<'id, 'curs, T> {
cur: Option<NodePtr<'id, T>>,
token: &'curs mut GhostToken<'id>,
}
impl <'id, 'curs, T> CursorMut<'id, 'curs, T> {
pub fn current(&mut self) -> Option<&mut T> {
if let Some(ref mut node) = self.cur {
Some(&mut node.borrow_mut(self.token).data)
} else {
None
}
}
pub fn move_next(&mut self) -> Result<(), ()> {
if let Some(ref mut node) = self.cur {
let next = node.borrow(self.token).next.clone();
self.cur = next;
Ok(())
} else {
Err(())
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment