Skip to content

Commit

Permalink
feat(cordyceps): rename cursor to cursor_front_mut (#227)
Browse files Browse the repository at this point in the history
This renames `List::cursor` to `List::cursor_front_mut` to prepare for
adding a `List::cursor_back_mut` and `cursor_front`/`cursor_back`,
similarly to `std::collections::LinkedList`'s cursor methods.

`List::cursor` is now deprecated.

Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw committed Jun 18, 2022
1 parent 96d14a6 commit b147738
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
13 changes: 12 additions & 1 deletion cordyceps/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,18 @@ impl<T: Linked<Links<T>> + ?Sized> List<T> {
/// however, it also permits modifying the *structure* of the list by
/// inserting or removing elements at the cursor's current position.
#[must_use]
#[deprecated(since = "0.2.2", note = "renamed to `List::cursor_front_mut`")]
pub fn cursor(&mut self) -> Cursor<'_, T> {
self.cursor_front_mut()
}

/// Returns a [`Cursor`] starting at the first element.
///
/// The [`Cursor`] type can be used as a mutable [`Iterator`]. In addition,
/// however, it also permits modifying the *structure* of the list by
/// inserting or removing elements at the cursor's current position.
#[must_use]
pub fn cursor_front_mut(&mut self) -> Cursor<'_, T> {
Cursor {
curr: self.head,
list: self,
Expand Down Expand Up @@ -649,7 +660,7 @@ impl<T: Linked<Links<T>> + ?Sized> List<T> {
where
F: FnMut(&T) -> bool,
{
let cursor = self.cursor();
let cursor = self.cursor_front_mut();
DrainFilter { cursor, pred }
}
}
Expand Down
4 changes: 2 additions & 2 deletions cordyceps/src/list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ fn drain_filter() {

// let mut list = List::<Entry<'_>>::new();

// assert_eq!(0, list.cursor().count());
// assert_eq!(0, list.cursor_front_mut().count());

// list.push_front(a.as_ref());
// list.push_front(b.as_ref());

// let mut i = list.cursor();
// let mut i = list.cursor_front_mut();
// assert_eq!(7, i.next().unwrap().val);
// assert_eq!(5, i.next().unwrap().val);
// assert!(i.next().is_none());
Expand Down
2 changes: 1 addition & 1 deletion cordyceps/src/list/tests/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn move_peek() {
one.as_ref(),
],
);
let mut cursor = list.cursor();
let mut cursor = list.cursor_front_mut();
assert_eq!(val(cursor.current()), Some(1));
assert_eq!(val(cursor.peek_next()), Some(2));
assert_eq!(val(cursor.peek_prev()), None);
Expand Down
4 changes: 2 additions & 2 deletions cordyceps/src/list/tests/owned_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ fn cursor_twice() {

// iterate over the list...
let mut i = 1;
for entry in list.cursor() {
for entry in list.cursor_front_mut() {
assert_eq!(entry.val, i);
i += 1;
}

// do it again; it should still work!
let mut i = 1;
for entry in list.cursor() {
for entry in list.cursor_front_mut() {
assert_eq!(entry.val, i);
i += 1;
}
Expand Down

0 comments on commit b147738

Please sign in to comment.