Skip to content

Commit fb6b0b1

Browse files
authored
Merge pull request #570 from Nitrokey/oldest-ordered-de-monomorphize
Remove generic from history_buf::OldestOrdered
2 parents e3d373f + 6bf9a98 commit fb6b0b1

File tree

2 files changed

+8
-49
lines changed

2 files changed

+8
-49
lines changed

CHANGELOG.md

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

1212
- `bytes::BufMut` is now implemented on `VecInner`.
13+
- Removed generic from `history_buf::OldestOrdered`.
1314

1415
### Fixed
1516

src/history_buf.rs

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,9 @@ impl<T, S: HistoryBufStorage<T> + ?Sized> HistoryBufInner<T, S> {
520520
/// assert_eq!(x, y)
521521
/// }
522522
/// ```
523-
pub fn oldest_ordered(&self) -> OldestOrderedInner<'_, T, S> {
523+
pub fn oldest_ordered(&self) -> OldestOrdered<'_, T> {
524524
let (old, new) = self.as_slices();
525-
OldestOrderedInner {
526-
phantom: PhantomData,
525+
OldestOrdered {
527526
inner: old.iter().chain(new),
528527
}
529528
}
@@ -612,62 +611,21 @@ where
612611
}
613612
}
614613

615-
/// Base struct for [`OldestOrdered`] and [`OldestOrderedView`], generic over the [`HistoryBufStorage`].
616-
///
617-
/// In most cases you should use [`OldestOrdered`] or [`OldestOrderedView`] directly. Only use this
618-
/// struct if you want to write code that's generic over both.
619-
pub struct OldestOrderedInner<'a, T, S: HistoryBufStorage<T> + ?Sized> {
620-
phantom: PhantomData<S>,
621-
inner: core::iter::Chain<core::slice::Iter<'a, T>, core::slice::Iter<'a, T>>,
622-
}
623-
624614
/// Double ended iterator on the underlying buffer ordered from the oldest data
625615
/// to the newest.
626-
///
627-
/// This type exists for backwards compatibility. It is always better to convert it to an [`OldestOrderedView`] with [`into_view`](OldestOrdered::into_view)
628-
pub type OldestOrdered<'a, T, const N: usize> =
629-
OldestOrderedInner<'a, T, OwnedHistoryBufStorage<T, N>>;
630-
631-
/// Double ended iterator on the underlying buffer ordered from the oldest data
632-
/// to the newest
633-
pub type OldestOrderedView<'a, T> = OldestOrderedInner<'a, T, ViewHistoryBufStorage<T>>;
634-
635-
impl<'a, T, const N: usize> OldestOrdered<'a, T, N> {
636-
/// Remove the `N` const-generic parameter from the iterator
637-
///
638-
/// For the opposite operation, see [`into_legacy_iter`](OldestOrderedView::into_legacy_iter)
639-
pub fn into_view(self) -> OldestOrderedView<'a, T> {
640-
OldestOrderedView {
641-
phantom: PhantomData,
642-
inner: self.inner,
643-
}
644-
}
645-
}
646-
647-
impl<'a, T> OldestOrderedView<'a, T> {
648-
/// Add back the `N` const-generic parameter to use it with APIs expecting the legacy type
649-
///
650-
/// You probably do not need this
651-
///
652-
/// For the opposite operation, see [`into_view`](OldestOrdered::into_view)
653-
pub fn into_legacy_iter<const N: usize>(self) -> OldestOrdered<'a, T, N> {
654-
OldestOrdered {
655-
phantom: PhantomData,
656-
inner: self.inner,
657-
}
658-
}
616+
pub struct OldestOrdered<'a, T> {
617+
inner: core::iter::Chain<core::slice::Iter<'a, T>, core::slice::Iter<'a, T>>,
659618
}
660619

661-
impl<T, S: HistoryBufStorage<T> + ?Sized> Clone for OldestOrderedInner<'_, T, S> {
620+
impl<T> Clone for OldestOrdered<'_, T> {
662621
fn clone(&self) -> Self {
663622
Self {
664-
phantom: PhantomData,
665623
inner: self.inner.clone(),
666624
}
667625
}
668626
}
669627

670-
impl<'a, T, S: HistoryBufStorage<T> + ?Sized> Iterator for OldestOrderedInner<'a, T, S> {
628+
impl<'a, T> Iterator for OldestOrdered<'a, T> {
671629
type Item = &'a T;
672630

673631
fn next(&mut self) -> Option<&'a T> {
@@ -679,7 +637,7 @@ impl<'a, T, S: HistoryBufStorage<T> + ?Sized> Iterator for OldestOrderedInner<'a
679637
}
680638
}
681639

682-
impl<T, const N: usize> DoubleEndedIterator for OldestOrdered<'_, T, N> {
640+
impl<T> DoubleEndedIterator for OldestOrdered<'_, T> {
683641
fn next_back(&mut self) -> Option<Self::Item> {
684642
self.inner.next_back()
685643
}

0 commit comments

Comments
 (0)