Skip to content

Commit 67164d0

Browse files
committed
Deduplicate implementations
1 parent 183d160 commit 67164d0

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/sorted_linked_list.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -581,11 +581,12 @@ where
581581
}
582582
}
583583

584-
impl<T, Idx, K> SortedLinkedListView<T, Idx, K>
584+
impl<T, Idx, K, S> SortedLinkedListInner<T, Idx, K, S>
585585
where
586586
T: Ord,
587587
Idx: SortedLinkedListIndex,
588588
K: Kind,
589+
S: SortedLinkedListStorage<T, Idx> + ?Sized,
589590
{
590591
/// Get an iterator over the sorted list.
591592
///
@@ -598,15 +599,15 @@ where
598599
/// ll.push(1).unwrap();
599600
/// ll.push(2).unwrap();
600601
///
601-
/// let mut iter = ll.as_view().iter();
602+
/// let mut iter = ll.iter();
602603
///
603604
/// assert_eq!(iter.next(), Some(&2));
604605
/// assert_eq!(iter.next(), Some(&1));
605606
/// assert_eq!(iter.next(), None);
606607
/// ```
607608
pub fn iter(&self) -> IterView<'_, T, Idx, K> {
608609
IterView {
609-
list: self,
610+
list: S::as_view(self),
610611
index: self.head,
611612
}
612613
}
@@ -645,7 +646,7 @@ where
645646
is_head: true,
646647
prev_index: Idx::none(),
647648
index: self.head,
648-
list: self,
649+
list: S::as_mut_view(self),
649650
maybe_changed: false,
650651
});
651652
}
@@ -658,7 +659,7 @@ where
658659
is_head: false,
659660
prev_index: unsafe { Idx::new_unchecked(current) },
660661
index: unsafe { Idx::new_unchecked(next) },
661-
list: self,
662+
list: S::as_mut_view(self),
662663
maybe_changed: false,
663664
});
664665
}
@@ -868,11 +869,12 @@ where
868869
// }
869870
// }
870871

871-
impl<T, Idx, K> fmt::Debug for SortedLinkedListView<T, Idx, K>
872+
impl<T, Idx, K, S> fmt::Debug for SortedLinkedListInner<T, Idx, K, S>
872873
where
873874
T: Ord + core::fmt::Debug,
874875
Idx: SortedLinkedListIndex,
875876
K: Kind,
877+
S: ?Sized + SortedLinkedListStorage<T, Idx>,
876878
{
877879
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
878880
f.debug_list().entries(self.iter()).finish()
@@ -986,22 +988,22 @@ mod tests {
986988
ll.push(2).unwrap();
987989
ll.push(3).unwrap();
988990

989-
let mut find = ll.as_mut_view().find_mut(|v| *v == 2).unwrap();
991+
let mut find = ll.find_mut(|v| *v == 2).unwrap();
990992

991993
*find += 1000;
992994
find.finish();
993995

994996
assert_eq!(ll.peek().unwrap(), &1002);
995997

996-
let mut find = ll.as_mut_view().find_mut(|v| *v == 3).unwrap();
998+
let mut find = ll.find_mut(|v| *v == 3).unwrap();
997999

9981000
*find += 1000;
9991001
find.finish();
10001002

10011003
assert_eq!(ll.peek().unwrap(), &1003);
10021004

10031005
// Remove largest element
1004-
ll.as_mut_view().find_mut(|v| *v == 1003).unwrap().pop();
1006+
ll.find_mut(|v| *v == 1003).unwrap().pop();
10051007

10061008
assert_eq!(ll.peek().unwrap(), &1002);
10071009
}
@@ -1021,7 +1023,7 @@ mod tests {
10211023
let mut ll: SortedLinkedList<u32, LinkedIndexUsize, Max, 3> = SortedLinkedList::new_usize();
10221024
ll.push(1).unwrap();
10231025

1024-
let mut find = ll.as_mut_view().find_mut(|v| *v == 1).unwrap();
1026+
let mut find = ll.find_mut(|v| *v == 1).unwrap();
10251027

10261028
*find += 1000;
10271029
find.finish();

0 commit comments

Comments
 (0)