.checked_sub(1).unwrap_or(0) → .saturating_sub(1)
This commit is contained in:
parent
efa32de15b
commit
9b2d03bd60
1 changed files with 4 additions and 4 deletions
|
|
@ -597,7 +597,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
|
|||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn cursor_back(&self) -> Cursor<'_, T, A> {
|
||||
Cursor { index: self.len.checked_sub(1).unwrap_or(0), current: self.tail, list: self }
|
||||
Cursor { index: self.len.saturating_sub(1), current: self.tail, list: self }
|
||||
}
|
||||
|
||||
/// Provides a cursor with editing operations at the back element.
|
||||
|
|
@ -607,7 +607,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
|
|||
#[must_use]
|
||||
#[unstable(feature = "linked_list_cursors", issue = "58533")]
|
||||
pub fn cursor_back_mut(&mut self) -> CursorMut<'_, T, A> {
|
||||
CursorMut { index: self.len.checked_sub(1).unwrap_or(0), current: self.tail, list: self }
|
||||
CursorMut { index: self.len.saturating_sub(1), current: self.tail, list: self }
|
||||
}
|
||||
|
||||
/// Returns `true` if the `LinkedList` is empty.
|
||||
|
|
@ -1432,7 +1432,7 @@ impl<'a, T, A: Allocator> Cursor<'a, T, A> {
|
|||
// No current. We're at the start of the list. Yield None and jump to the end.
|
||||
None => {
|
||||
self.current = self.list.tail;
|
||||
self.index = self.list.len().checked_sub(1).unwrap_or(0);
|
||||
self.index = self.list.len().saturating_sub(1);
|
||||
}
|
||||
// Have a prev. Yield it and go to the previous element.
|
||||
Some(current) => unsafe {
|
||||
|
|
@ -1559,7 +1559,7 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
|
|||
// No current. We're at the start of the list. Yield None and jump to the end.
|
||||
None => {
|
||||
self.current = self.list.tail;
|
||||
self.index = self.list.len().checked_sub(1).unwrap_or(0);
|
||||
self.index = self.list.len().saturating_sub(1);
|
||||
}
|
||||
// Have a prev. Yield it and go to the previous element.
|
||||
Some(current) => unsafe {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue