Skip to content

Commit 1fdf663

Browse files
committed
SortedLinkedList::pop: change return type to match std::vec::pop
1 parent 2e71c18 commit 1fdf663

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
4545
### Changed
4646

4747
- Changed `stable_deref_trait` to a platform-dependent dependency.
48+
- Changed `SortedLinkedList::pop` return type from `Result<T, ()>` to `Option<T>` to match `std::vec::pop`.
4849

4950
### Fixed
5051

src/sorted_linked_list.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,10 @@ where
390390
/// *find += 1000;
391391
/// find.finish();
392392
///
393-
/// assert_eq!(ll.pop(), Ok(1002));
394-
/// assert_eq!(ll.pop(), Ok(3));
395-
/// assert_eq!(ll.pop(), Ok(1));
396-
/// assert_eq!(ll.pop(), Err(()));
393+
/// assert_eq!(ll.pop(), Some(1002));
394+
/// assert_eq!(ll.pop(), Some(3));
395+
/// assert_eq!(ll.pop(), Some(1));
396+
/// assert_eq!(ll.pop(), None);
397397
/// ```
398398
pub fn find_mut<F>(&mut self, mut f: F) -> Option<FindMutInner<'_, T, Idx, K, S>>
399399
where
@@ -491,16 +491,15 @@ where
491491
/// ll.push(1).unwrap();
492492
/// ll.push(2).unwrap();
493493
///
494-
/// assert_eq!(ll.pop(), Ok(2));
495-
/// assert_eq!(ll.pop(), Ok(1));
496-
/// assert_eq!(ll.pop(), Err(()));
494+
/// assert_eq!(ll.pop(), Some(2));
495+
/// assert_eq!(ll.pop(), Some(1));
496+
/// assert_eq!(ll.pop(), None);
497497
/// ```
498-
#[allow(clippy::result_unit_err)]
499-
pub fn pop(&mut self) -> Result<T, ()> {
498+
pub fn pop(&mut self) -> Option<T> {
500499
if !self.is_empty() {
501-
Ok(unsafe { self.pop_unchecked() })
500+
Some(unsafe { self.pop_unchecked() })
502501
} else {
503-
Err(())
502+
None
504503
}
505504
}
506505

@@ -652,9 +651,9 @@ where
652651
/// let mut find = ll.find_mut(|v| *v == 2).unwrap();
653652
/// find.pop();
654653
///
655-
/// assert_eq!(ll.pop(), Ok(3));
656-
/// assert_eq!(ll.pop(), Ok(1));
657-
/// assert_eq!(ll.pop(), Err(()));
654+
/// assert_eq!(ll.pop(), Some(3));
655+
/// assert_eq!(ll.pop(), Some(1));
656+
/// assert_eq!(ll.pop(), None);
658657
/// ```
659658
#[inline]
660659
pub fn pop(mut self) -> T {
@@ -685,10 +684,10 @@ where
685684
/// *find += 1000;
686685
/// find.finish(); // Will resort, we accessed (and updated) the value.
687686
///
688-
/// assert_eq!(ll.pop(), Ok(1002));
689-
/// assert_eq!(ll.pop(), Ok(3));
690-
/// assert_eq!(ll.pop(), Ok(1));
691-
/// assert_eq!(ll.pop(), Err(()));
687+
/// assert_eq!(ll.pop(), Some(1002));
688+
/// assert_eq!(ll.pop(), Some(3));
689+
/// assert_eq!(ll.pop(), Some(1));
690+
/// assert_eq!(ll.pop(), None);
692691
/// ```
693692
#[inline]
694693
pub fn finish(self) {

0 commit comments

Comments
 (0)