diff --git a/cordyceps/src/list.rs b/cordyceps/src/list.rs index b722b7c0..63dda8ee 100644 --- a/cordyceps/src/list.rs +++ b/cordyceps/src/list.rs @@ -599,7 +599,18 @@ impl> + ?Sized> List { /// 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, @@ -649,7 +660,7 @@ impl> + ?Sized> List { where F: FnMut(&T) -> bool, { - let cursor = self.cursor(); + let cursor = self.cursor_front_mut(); DrainFilter { cursor, pred } } } diff --git a/cordyceps/src/list/tests.rs b/cordyceps/src/list/tests.rs index b08094c9..96048f81 100644 --- a/cordyceps/src/list/tests.rs +++ b/cordyceps/src/list/tests.rs @@ -297,12 +297,12 @@ fn drain_filter() { // let mut list = List::>::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()); diff --git a/cordyceps/src/list/tests/cursor.rs b/cordyceps/src/list/tests/cursor.rs index 92af68be..d29992e4 100644 --- a/cordyceps/src/list/tests/cursor.rs +++ b/cordyceps/src/list/tests/cursor.rs @@ -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); diff --git a/cordyceps/src/list/tests/owned_entry.rs b/cordyceps/src/list/tests/owned_entry.rs index d806cb92..c8768d48 100644 --- a/cordyceps/src/list/tests/owned_entry.rs +++ b/cordyceps/src/list/tests/owned_entry.rs @@ -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; }