Skip to content

Commit b8a4253

Browse files
authored
Merge pull request #532 from newAM/sorted-linked-list-pop-ret-type
SortedLinkedList::pop: change return type to match std::vec::pop
2 parents fefcba7 + 1fdf663 commit b8a4253

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
@@ -465,10 +465,10 @@ where
465465
/// *find += 1000;
466466
/// find.finish();
467467
///
468-
/// assert_eq!(ll.pop(), Ok(1002));
469-
/// assert_eq!(ll.pop(), Ok(3));
470-
/// assert_eq!(ll.pop(), Ok(1));
471-
/// assert_eq!(ll.pop(), Err(()));
468+
/// assert_eq!(ll.pop(), Some(1002));
469+
/// assert_eq!(ll.pop(), Some(3));
470+
/// assert_eq!(ll.pop(), Some(1));
471+
/// assert_eq!(ll.pop(), None);
472472
/// ```
473473
pub fn find_mut<F>(&mut self, mut f: F) -> Option<FindMutInner<'_, T, Idx, K, S>>
474474
where
@@ -566,16 +566,15 @@ where
566566
/// ll.push(1).unwrap();
567567
/// ll.push(2).unwrap();
568568
///
569-
/// assert_eq!(ll.pop(), Ok(2));
570-
/// assert_eq!(ll.pop(), Ok(1));
571-
/// assert_eq!(ll.pop(), Err(()));
569+
/// assert_eq!(ll.pop(), Some(2));
570+
/// assert_eq!(ll.pop(), Some(1));
571+
/// assert_eq!(ll.pop(), None);
572572
/// ```
573-
#[allow(clippy::result_unit_err)]
574-
pub fn pop(&mut self) -> Result<T, ()> {
573+
pub fn pop(&mut self) -> Option<T> {
575574
if !self.is_empty() {
576-
Ok(unsafe { self.pop_unchecked() })
575+
Some(unsafe { self.pop_unchecked() })
577576
} else {
578-
Err(())
577+
None
579578
}
580579
}
581580

@@ -730,9 +729,9 @@ where
730729
/// let mut find = ll.find_mut(|v| *v == 2).unwrap();
731730
/// find.pop();
732731
///
733-
/// assert_eq!(ll.pop(), Ok(3));
734-
/// assert_eq!(ll.pop(), Ok(1));
735-
/// assert_eq!(ll.pop(), Err(()));
732+
/// assert_eq!(ll.pop(), Some(3));
733+
/// assert_eq!(ll.pop(), Some(1));
734+
/// assert_eq!(ll.pop(), None);
736735
/// ```
737736
#[inline]
738737
pub fn pop(mut self) -> T {
@@ -763,10 +762,10 @@ where
763762
/// *find += 1000;
764763
/// find.finish(); // Will resort, we accessed (and updated) the value.
765764
///
766-
/// assert_eq!(ll.pop(), Ok(1002));
767-
/// assert_eq!(ll.pop(), Ok(3));
768-
/// assert_eq!(ll.pop(), Ok(1));
769-
/// assert_eq!(ll.pop(), Err(()));
765+
/// assert_eq!(ll.pop(), Some(1002));
766+
/// assert_eq!(ll.pop(), Some(3));
767+
/// assert_eq!(ll.pop(), Some(1));
768+
/// assert_eq!(ll.pop(), None);
770769
/// ```
771770
#[inline]
772771
pub fn finish(self) {

0 commit comments

Comments
 (0)