Add non-mutable methods to Cursor
This commit is contained in:
parent
a981be75cc
commit
e77acf7d27
@ -1243,6 +1243,20 @@ pub fn peek_prev(&self) -> Option<&'a T> {
|
||||
prev.map(|prev| &(*prev.as_ptr()).element)
|
||||
}
|
||||
}
|
||||
|
||||
/// Provides a reference to the front element of the cursor's parent list,
|
||||
/// or None if the list is empty.
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn front(&self) -> Option<&T> {
|
||||
self.list.front()
|
||||
}
|
||||
|
||||
/// Provides a reference to the back element of the cursor's parent list,
|
||||
/// or None if the list is empty.
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn back(&self) -> Option<&T> {
|
||||
self.list.back()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> CursorMut<'a, T> {
|
||||
|
@ -456,6 +456,9 @@ fn test_cursor_pop_front_back() {
|
||||
c.move_prev();
|
||||
c.move_prev();
|
||||
assert_eq!(c.pop_back(), Some(6));
|
||||
let c = c.as_cursor();
|
||||
assert_eq!(c.front(), Some(&2));
|
||||
assert_eq!(c.back(), Some(&5));
|
||||
drop(c);
|
||||
assert_eq!(ll, (2..6).collect());
|
||||
check_links(&ll);
|
||||
|
Loading…
Reference in New Issue
Block a user