SortedLinkedList::pop: change return type to match std::vec::pop

This commit is contained in:
Alex Martens 2025-03-09 10:37:32 -07:00
parent 2e71c18252
commit 1fdf663927
2 changed files with 18 additions and 18 deletions

View File

@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- Changed `stable_deref_trait` to a platform-dependent dependency.
- Changed `SortedLinkedList::pop` return type from `Result<T, ()>` to `Option<T>` to match `std::vec::pop`.
### Fixed

View File

@ -390,10 +390,10 @@ where
/// *find += 1000;
/// find.finish();
///
/// assert_eq!(ll.pop(), Ok(1002));
/// assert_eq!(ll.pop(), Ok(3));
/// assert_eq!(ll.pop(), Ok(1));
/// assert_eq!(ll.pop(), Err(()));
/// assert_eq!(ll.pop(), Some(1002));
/// assert_eq!(ll.pop(), Some(3));
/// assert_eq!(ll.pop(), Some(1));
/// assert_eq!(ll.pop(), None);
/// ```
pub fn find_mut<F>(&mut self, mut f: F) -> Option<FindMutInner<'_, T, Idx, K, S>>
where
@ -491,16 +491,15 @@ where
/// ll.push(1).unwrap();
/// ll.push(2).unwrap();
///
/// assert_eq!(ll.pop(), Ok(2));
/// assert_eq!(ll.pop(), Ok(1));
/// assert_eq!(ll.pop(), Err(()));
/// assert_eq!(ll.pop(), Some(2));
/// assert_eq!(ll.pop(), Some(1));
/// assert_eq!(ll.pop(), None);
/// ```
#[allow(clippy::result_unit_err)]
pub fn pop(&mut self) -> Result<T, ()> {
pub fn pop(&mut self) -> Option<T> {
if !self.is_empty() {
Ok(unsafe { self.pop_unchecked() })
Some(unsafe { self.pop_unchecked() })
} else {
Err(())
None
}
}
@ -652,9 +651,9 @@ where
/// let mut find = ll.find_mut(|v| *v == 2).unwrap();
/// find.pop();
///
/// assert_eq!(ll.pop(), Ok(3));
/// assert_eq!(ll.pop(), Ok(1));
/// assert_eq!(ll.pop(), Err(()));
/// assert_eq!(ll.pop(), Some(3));
/// assert_eq!(ll.pop(), Some(1));
/// assert_eq!(ll.pop(), None);
/// ```
#[inline]
pub fn pop(mut self) -> T {
@ -685,10 +684,10 @@ where
/// *find += 1000;
/// find.finish(); // Will resort, we accessed (and updated) the value.
///
/// assert_eq!(ll.pop(), Ok(1002));
/// assert_eq!(ll.pop(), Ok(3));
/// assert_eq!(ll.pop(), Ok(1));
/// assert_eq!(ll.pop(), Err(()));
/// assert_eq!(ll.pop(), Some(1002));
/// assert_eq!(ll.pop(), Some(3));
/// assert_eq!(ll.pop(), Some(1));
/// assert_eq!(ll.pop(), None);
/// ```
#[inline]
pub fn finish(self) {