diff options
| author | Pavel Grigorenko <GrigorenkoPV@ya.ru> | 2024-07-01 00:08:42 +0300 |
|---|---|---|
| committer | Pavel Grigorenko <GrigorenkoPV@ya.ru> | 2024-07-01 00:22:09 +0300 |
| commit | 23e5468a09b7cfcb62f69dc18bb1f49c5e69b2b5 (patch) | |
| tree | 3304f7663c3de81ddffe68f61e2965228225589b | |
| parent | ef3d6fd7002500af0a985f70d3ac5152623c1396 (diff) | |
| download | rust-23e5468a09b7cfcb62f69dc18bb1f49c5e69b2b5.tar.gz rust-23e5468a09b7cfcb62f69dc18bb1f49c5e69b2b5.zip | |
LinkedList's Cursor: method to get a ref to the cursor's list
| -rw-r--r-- | library/alloc/src/collections/linked_list.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 01510a61405..077483a174b 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -1495,6 +1495,14 @@ impl<'a, T, A: Allocator> Cursor<'a, T, A> { pub fn back(&self) -> Option<&'a T> { self.list.back() } + + /// Provides a reference to the cursor's parent list. + #[must_use] + #[inline(always)] + #[unstable(feature = "linked_list_cursors", issue = "58533")] + pub fn as_list(&self) -> &'a LinkedList<T, A> { + self.list + } } impl<'a, T, A: Allocator> CursorMut<'a, T, A> { @@ -1605,6 +1613,18 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> { pub fn as_cursor(&self) -> Cursor<'_, T, A> { Cursor { list: self.list, current: self.current, index: self.index } } + + /// Provides a read-only reference to the cursor's parent list. + /// + /// The lifetime of the returned reference is bound to that of the + /// `CursorMut`, which means it cannot outlive the `CursorMut` and that the + /// `CursorMut` is frozen for the lifetime of the reference. + #[must_use] + #[inline(always)] + #[unstable(feature = "linked_list_cursors", issue = "58533")] + pub fn as_list(&self) -> &LinkedList<T, A> { + self.list + } } // Now the list editing operations |
