Skip to content

Commit e77acf7

Browse files
committed
Add non-mutable methods to Cursor
1 parent a981be7 commit e77acf7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

library/alloc/src/collections/linked_list.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,20 @@ impl<'a, T> Cursor<'a, T> {
12431243
prev.map(|prev| &(*prev.as_ptr()).element)
12441244
}
12451245
}
1246+
1247+
/// Provides a reference to the front element of the cursor's parent list,
1248+
/// or None if the list is empty.
1249+
#[unstable(feature = "linked_list_cursors", issue = "58533")]
1250+
pub fn front(&self) -> Option<&T> {
1251+
self.list.front()
1252+
}
1253+
1254+
/// Provides a reference to the back element of the cursor's parent list,
1255+
/// or None if the list is empty.
1256+
#[unstable(feature = "linked_list_cursors", issue = "58533")]
1257+
pub fn back(&self) -> Option<&T> {
1258+
self.list.back()
1259+
}
12461260
}
12471261

12481262
impl<'a, T> CursorMut<'a, T> {

library/alloc/src/collections/linked_list/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ fn test_cursor_pop_front_back() {
456456
c.move_prev();
457457
c.move_prev();
458458
assert_eq!(c.pop_back(), Some(6));
459+
let c = c.as_cursor();
460+
assert_eq!(c.front(), Some(&2));
461+
assert_eq!(c.back(), Some(&5));
459462
drop(c);
460463
assert_eq!(ll, (2..6).collect());
461464
check_links(&ll);

0 commit comments

Comments
 (0)