///
/// This `struct` is created by [`LinkedList::iter()`]. See its
/// documentation for more.
+#[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Iter<'a, T: 'a> {
head: Option<NonNull<Node<T>>>,
///
/// This `struct` is created by [`LinkedList::iter_mut()`]. See its
/// documentation for more.
+#[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IterMut<'a, T: 'a> {
head: Option<NonNull<Node<T>>>,
#[inline]
#[rustc_const_stable(feature = "const_linked_list_new", since = "1.32.0")]
#[stable(feature = "rust1", since = "1.0.0")]
+ #[must_use]
pub const fn new() -> Self {
LinkedList { head: None, tail: None, len: 0, marker: PhantomData }
}
///
/// The cursor is pointing to the "ghost" non-element if the list is empty.
#[inline]
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn cursor_front(&self) -> Cursor<'_, T> {
Cursor { index: 0, current: self.head, list: self }
///
/// The cursor is pointing to the "ghost" non-element if the list is empty.
#[inline]
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn cursor_front_mut(&mut self) -> CursorMut<'_, T> {
CursorMut { index: 0, current: self.head, list: self }
///
/// The cursor is pointing to the "ghost" non-element if the list is empty.
#[inline]
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn cursor_back(&self) -> Cursor<'_, T> {
Cursor { index: self.len.checked_sub(1).unwrap_or(0), current: self.tail, list: self }
///
/// The cursor is pointing to the "ghost" non-element if the list is empty.
#[inline]
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn cursor_back_mut(&mut self) -> CursorMut<'_, T> {
CursorMut { index: self.len.checked_sub(1).unwrap_or(0), current: self.tail, list: self }
/// assert_eq!(dl.front(), Some(&1));
/// ```
#[inline]
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn front(&self) -> Option<&T> {
unsafe { self.head.as_ref().map(|node| &node.as_ref().element) }
/// assert_eq!(dl.front(), Some(&5));
/// ```
#[inline]
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn front_mut(&mut self) -> Option<&mut T> {
unsafe { self.head.as_mut().map(|node| &mut node.as_mut().element) }
/// assert_eq!(dl.back(), Some(&1));
/// ```
#[inline]
+ #[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn back(&self) -> Option<&T> {
unsafe { self.tail.as_ref().map(|node| &node.as_ref().element) }
///
/// This returns `None` if the cursor is currently pointing to the
/// "ghost" non-element.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn index(&self) -> Option<usize> {
let _ = self.current?;
///
/// This returns `None` if the cursor is currently pointing to the
/// "ghost" non-element.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn current(&self) -> Option<&'a T> {
unsafe { self.current.map(|current| &(*current.as_ptr()).element) }
/// If the cursor is pointing to the "ghost" non-element then this returns
/// the first element of the `LinkedList`. If it is pointing to the last
/// element of the `LinkedList` then this returns `None`.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn peek_next(&self) -> Option<&'a T> {
unsafe {
/// If the cursor is pointing to the "ghost" non-element then this returns
/// the last element of the `LinkedList`. If it is pointing to the first
/// element of the `LinkedList` then this returns `None`.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn peek_prev(&self) -> Option<&'a T> {
unsafe {
/// Provides a reference to the front element of the cursor's parent list,
/// or None if the list is empty.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn front(&self) -> Option<&'a T> {
self.list.front()
/// Provides a reference to the back element of the cursor's parent list,
/// or None if the list is empty.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn back(&self) -> Option<&'a T> {
self.list.back()
///
/// This returns `None` if the cursor is currently pointing to the
/// "ghost" non-element.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn index(&self) -> Option<usize> {
let _ = self.current?;
///
/// This returns `None` if the cursor is currently pointing to the
/// "ghost" non-element.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn current(&mut self) -> Option<&mut T> {
unsafe { self.current.map(|current| &mut (*current.as_ptr()).element) }
/// The lifetime of the returned `Cursor` 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 `Cursor`.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn as_cursor(&self) -> Cursor<'_, T> {
Cursor { list: self.list, current: self.current, index: self.index }
/// Provides a reference to the front element of the cursor's parent list,
/// or None if the list is empty.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn front(&self) -> Option<&T> {
self.list.front()
/// Provides a mutable reference to the front element of the cursor's
/// parent list, or None if the list is empty.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn front_mut(&mut self) -> Option<&mut T> {
self.list.front_mut()
/// Provides a reference to the back element of the cursor's parent list,
/// or None if the list is empty.
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn back(&self) -> Option<&T> {
self.list.back()
/// assert_eq!(contents.next(), Some(0));
/// assert_eq!(contents.next(), None);
/// ```
+ #[must_use]
#[unstable(feature = "linked_list_cursors", issue = "58533")]
pub fn back_mut(&mut self) -> Option<&mut T> {
self.list.back_mut()