From a849a60067b8c559e407c00aa68c3d7d9f93f44b Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Fri, 4 Apr 2025 15:49:19 -0500 Subject: [PATCH] Rename `histbuf` to `history_buf` and `HistoryBuffer.*` to `HistoryBuf.*` --- src/de.rs | 8 +- src/{histbuf.rs => history_buf.rs} | 253 +++++++++++++++-------------- src/lib.rs | 6 +- src/ser.rs | 4 +- tests/cpass.rs | 8 +- 5 files changed, 140 insertions(+), 139 deletions(-) rename src/{histbuf.rs => history_buf.rs} (72%) diff --git a/src/de.rs b/src/de.rs index 1c8c1c48..de04202a 100644 --- a/src/de.rs +++ b/src/de.rs @@ -1,5 +1,5 @@ use crate::{ - binary_heap::Kind as BinaryHeapKind, len_type::LenType, BinaryHeap, Deque, HistoryBuffer, + binary_heap::Kind as BinaryHeapKind, len_type::LenType, BinaryHeap, Deque, HistoryBuf, IndexMap, IndexSet, LinearMap, String, Vec, }; use core::{ @@ -174,7 +174,7 @@ where } } -impl<'de, T, const N: usize> Deserialize<'de> for HistoryBuffer +impl<'de, T, const N: usize> Deserialize<'de> for HistoryBuf where T: Deserialize<'de>, { @@ -188,7 +188,7 @@ where where T: Deserialize<'de>, { - type Value = HistoryBuffer; + type Value = HistoryBuf; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str("a sequence") @@ -198,7 +198,7 @@ where where A: SeqAccess<'de>, { - let mut values = HistoryBuffer::new(); + let mut values = HistoryBuf::new(); while let Some(value) = seq.next_element()? { values.write(value); diff --git a/src/histbuf.rs b/src/history_buf.rs similarity index 72% rename from src/histbuf.rs rename to src/history_buf.rs index cc4b4922..ab251c0d 100644 --- a/src/histbuf.rs +++ b/src/history_buf.rs @@ -6,10 +6,10 @@ //! //! # Examples //! ``` -//! use heapless::HistoryBuffer; +//! use heapless::HistoryBuf; //! //! // Initialize a new buffer with 8 elements. -//! let mut buf = HistoryBuffer::<_, 8>::new(); +//! let mut buf = HistoryBuf::<_, 8>::new(); //! //! // Starts with no data //! assert_eq!(buf.recent(), None); @@ -41,115 +41,114 @@ use core::slice; mod storage { use core::mem::MaybeUninit; - use super::{HistoryBufferInner, HistoryBufferView}; + use super::{HistoryBufInner, HistoryBufView}; /// Trait defining how data for a container is stored. /// /// There's two implementations available: /// - /// - [`OwnedHistBufStorage`]: stores the data in an array `[T; N]` whose size is known at compile time. - /// - [`ViewHistBufStorage`]: stores the data in an unsized `[T]`. + /// - [`OwnedHistoryBufStorage`]: stores the data in an array `[T; N]` whose size is known at compile time. + /// - [`ViewHistoryBufStorage`]: stores the data in an unsized `[T]`. /// - /// This allows [`HistoryBuffer`] to be generic over either sized or unsized storage. The [`histbuf`] - /// module contains a [`HistoryBufferInner`] struct that's generic on [`HistBufStorage`], + /// This allows [`HistoryBuf`] to be generic over either sized or unsized storage. The [`histbuf`] + /// module contains a [`HistoryBufInner`] struct that's generic on [`HistoryBufStorage`], /// and two type aliases for convenience: /// - /// - [`HistBuf`](super::HistoryBuffer) = `HistoryBufferInner>` - /// - [`HistBufView`](super::HistoryBufferView) = `HistoryBufferInner>` + /// - [`HistoryBuf`](super::HistoryBuf) = `HistoryBufInner>` + /// - [`HistoryBufView`](super::HistoryBufView) = `HistoryBufInner>` /// - /// `HistoryBuffer` can be unsized into `HistoryBufferView`, either by unsizing coercions such as `&mut HistoryBuffer -> &mut HistoryBufferView` or - /// `Box -> Box`, or explicitly with [`.as_view()`](super::HistoryBuffer::as_view) or [`.as_mut_view()`](super::HistoryBuffer::as_mut_view). + /// `HistoryBuf` can be unsized into `HistoryBufView`, either by unsizing coercions such as `&mut HistoryBuf -> &mut HistoryBufView` or + /// `Box -> Box`, or explicitly with [`.as_view()`](super::HistoryBuf::as_view) or [`.as_mut_view()`](super::HistoryBuf::as_mut_view). /// /// This trait is sealed, so you cannot implement it for your own types. You can only use /// the implementations provided by this crate. /// - /// [`HistoryBufferInner`]: super::HistoryBufferInner - /// [`HistoryBuffer`]: super::HistoryBuffer - /// [`HistoryBufferView`]: super::HistoryBufferView + /// [`HistoryBufInner`]: super::HistoryBufInner + /// [`HistoryBuf`]: super::HistoryBuf + /// [`HistoryBufView`]: super::HistoryBufView /// [`histbuf`]: super #[allow(private_bounds)] - pub trait HistBufStorage: HistBufSealedStorage {} + pub trait HistoryBufStorage: HistoryBufSealedStorage {} - pub trait HistBufSealedStorage { - // part of the sealed trait so that no trait is publicly implemented by `OwnedHistBufStorage` besides `Storage` + pub trait HistoryBufSealedStorage { + // part of the sealed trait so that no trait is publicly implemented by `OwnedHistoryBufStorage` besides `Storage` fn borrow(&self) -> &[MaybeUninit]; fn borrow_mut(&mut self) -> &mut [MaybeUninit]; - fn as_hist_buf_view(this: &HistoryBufferInner) -> &HistoryBufferView + fn as_hist_buf_view(this: &HistoryBufInner) -> &HistoryBufView where - Self: HistBufStorage; - fn as_hist_buf_mut_view( - this: &mut HistoryBufferInner, - ) -> &mut HistoryBufferView + Self: HistoryBufStorage; + fn as_hist_buf_mut_view(this: &mut HistoryBufInner) -> &mut HistoryBufView where - Self: HistBufStorage; + Self: HistoryBufStorage; } // One sealed layer of indirection to hide the internal details (The MaybeUninit). - pub struct HistBufStorageInner { + pub struct HistoryBufStorageInner { pub(crate) buffer: T, } - /// Implementation of [`HistBufStorage`] that stores the data in an array `[T; N]` whose size is known at compile time. - pub type OwnedHistBufStorage = HistBufStorageInner<[MaybeUninit; N]>; - /// Implementation of [`HistBufStorage`] that stores the data in an unsized `[T]`. - pub type ViewHistBufStorage = HistBufStorageInner<[MaybeUninit]>; + /// Implementation of [`HistoryBufStorage`] that stores the data in an array `[T; N]` whose size is known at compile time. + pub type OwnedHistoryBufStorage = + HistoryBufStorageInner<[MaybeUninit; N]>; + /// Implementation of [`HistoryBufStorage`] that stores the data in an unsized `[T]`. + pub type ViewHistoryBufStorage = HistoryBufStorageInner<[MaybeUninit]>; - impl HistBufSealedStorage for OwnedHistBufStorage { + impl HistoryBufSealedStorage for OwnedHistoryBufStorage { fn borrow(&self) -> &[MaybeUninit] { &self.buffer } fn borrow_mut(&mut self) -> &mut [MaybeUninit] { &mut self.buffer } - fn as_hist_buf_view(this: &HistoryBufferInner) -> &HistoryBufferView + fn as_hist_buf_view(this: &HistoryBufInner) -> &HistoryBufView where - Self: HistBufStorage, + Self: HistoryBufStorage, { this } - fn as_hist_buf_mut_view(this: &mut HistoryBufferInner) -> &mut HistoryBufferView + fn as_hist_buf_mut_view(this: &mut HistoryBufInner) -> &mut HistoryBufView where - Self: HistBufStorage, + Self: HistoryBufStorage, { this } } - impl HistBufStorage for OwnedHistBufStorage {} + impl HistoryBufStorage for OwnedHistoryBufStorage {} - impl HistBufSealedStorage for ViewHistBufStorage { + impl HistoryBufSealedStorage for ViewHistoryBufStorage { fn borrow(&self) -> &[MaybeUninit] { &self.buffer } fn borrow_mut(&mut self) -> &mut [MaybeUninit] { &mut self.buffer } - fn as_hist_buf_view(this: &HistoryBufferInner) -> &HistoryBufferView + fn as_hist_buf_view(this: &HistoryBufInner) -> &HistoryBufView where - Self: HistBufStorage, + Self: HistoryBufStorage, { this } - fn as_hist_buf_mut_view(this: &mut HistoryBufferInner) -> &mut HistoryBufferView + fn as_hist_buf_mut_view(this: &mut HistoryBufInner) -> &mut HistoryBufView where - Self: HistBufStorage, + Self: HistoryBufStorage, { this } } - impl HistBufStorage for ViewHistBufStorage {} + impl HistoryBufStorage for ViewHistoryBufStorage {} } -pub use storage::{HistBufStorage, OwnedHistBufStorage, ViewHistBufStorage}; +pub use storage::{HistoryBufStorage, OwnedHistoryBufStorage, ViewHistoryBufStorage}; -use storage::HistBufStorageInner; +use storage::HistoryBufStorageInner; -use self::storage::HistBufSealedStorage; +use self::storage::HistoryBufSealedStorage; -/// Base struct for [`HistoryBuffer`] and [`HistoryBufferView`], generic over the [`HistBufStorage`]. +/// Base struct for [`HistoryBuf`] and [`HistoryBufView`], generic over the [`HistoryBufStorage`]. /// -/// In most cases you should use [`HistoryBuffer`] or [`HistoryBufferView`] directly. Only use this +/// In most cases you should use [`HistoryBuf`] or [`HistoryBufView`] directly. Only use this /// struct if you want to write code that's generic over both. -pub struct HistoryBufferInner + ?Sized> { +pub struct HistoryBufInner + ?Sized> { // This phantomdata is required because otherwise rustc thinks that `T` is not used phantom: PhantomData, write_at: usize, @@ -165,10 +164,10 @@ pub struct HistoryBufferInner + ?Sized> { /// /// # Examples /// ``` -/// use heapless::HistoryBuffer; +/// use heapless::HistoryBuf; /// /// // Initialize a new buffer with 8 elements. -/// let mut buf = HistoryBuffer::<_, 8>::new(); +/// let mut buf = HistoryBuf::<_, 8>::new(); /// /// // Starts with no data /// assert_eq!(buf.recent(), None); @@ -189,19 +188,19 @@ pub struct HistoryBufferInner + ?Sized> { /// let avg = buf.as_slice().iter().sum::() / buf.len(); /// assert_eq!(avg, 4); /// ``` -pub type HistoryBuffer = HistoryBufferInner>; +pub type HistoryBuf = HistoryBufInner>; -/// A "view" into a [`HistoryBuffer`] +/// A "view" into a [`HistoryBuf`] /// -/// Unlike [`HistoryBuffer`], it doesn't have the `const N: usize` in its type signature. +/// Unlike [`HistoryBuf`], it doesn't have the `const N: usize` in its type signature. /// /// # Examples /// ``` -/// use heapless::histbuf::{HistoryBuffer, HistoryBufferView}; +/// use heapless::history_buf::{HistoryBuf, HistoryBufView}; /// /// // Initialize a new buffer with 8 elements. -/// let mut owned_buf = HistoryBuffer::<_, 8>::new(); -/// let buf: &mut HistoryBufferView<_> = &mut owned_buf; +/// let mut owned_buf = HistoryBuf::<_, 8>::new(); +/// let buf: &mut HistoryBufView<_> = &mut owned_buf; /// /// // Starts with no data /// assert_eq!(buf.recent(), None); @@ -222,22 +221,22 @@ pub type HistoryBuffer = HistoryBufferInner() / buf.len(); /// assert_eq!(avg, 4); /// ``` -pub type HistoryBufferView = HistoryBufferInner>; +pub type HistoryBufView = HistoryBufInner>; -impl HistoryBuffer { +impl HistoryBuf { const INIT: MaybeUninit = MaybeUninit::uninit(); /// Constructs a new history buffer. /// - /// The construction of a `HistoryBuffer` works in `const` contexts. + /// The construction of a `HistoryBuf` works in `const` contexts. /// /// # Examples /// /// ``` - /// use heapless::HistoryBuffer; + /// use heapless::HistoryBuf; /// /// // Allocate a 16-element buffer on the stack - /// let x: HistoryBuffer = HistoryBuffer::new(); + /// let x: HistoryBuf = HistoryBuf::new(); /// assert_eq!(x.len(), 0); /// ``` #[inline] @@ -248,7 +247,7 @@ impl HistoryBuffer { Self { phantom: PhantomData, - data: HistBufStorageInner { + data: HistoryBufStorageInner { buffer: [Self::INIT; N], }, write_at: 0, @@ -257,7 +256,7 @@ impl HistoryBuffer { } } -impl HistoryBuffer +impl HistoryBuf where T: Copy + Clone, { @@ -266,10 +265,10 @@ where /// # Examples /// /// ``` - /// use heapless::HistoryBuffer; + /// use heapless::HistoryBuf; /// /// // Allocate a 16-element buffer on the stack - /// let mut x: HistoryBuffer = HistoryBuffer::new_with(4); + /// let mut x: HistoryBuf = HistoryBuf::new_with(4); /// // All elements are four /// assert_eq!(x.as_slice(), [4; 16]); /// ``` @@ -277,7 +276,7 @@ where pub fn new_with(t: T) -> Self { Self { phantom: PhantomData, - data: HistBufStorageInner { + data: HistoryBufStorageInner { buffer: [MaybeUninit::new(t); N], }, write_at: 0, @@ -285,18 +284,20 @@ where } } } -impl + ?Sized> HistoryBufferInner { - /// Get a reference to the `HistoryBuffer`, erasing the `N` const-generic. + +impl + ?Sized> HistoryBufInner { + /// Get a reference to the `HistoryBuf`, erasing the `N` const-generic. #[inline] - pub fn as_view(&self) -> &HistoryBufferView { + pub fn as_view(&self) -> &HistoryBufView { S::as_hist_buf_view(self) } - /// Get a mutable reference to the `HistoryBuffer`, erasing the `N` const-generic. + /// Get a mutable reference to the `HistoryBuf`, erasing the `N` const-generic. #[inline] - pub fn as_mut_view(&mut self) -> &mut HistoryBufferView { + pub fn as_mut_view(&mut self) -> &mut HistoryBufView { S::as_hist_buf_mut_view(self) } + /// Clears the buffer, replacing every element with the given value. pub fn clear_with(&mut self, t: T) { // SAFETY: we reset the values just after @@ -310,7 +311,7 @@ impl + ?Sized> HistoryBufferInner { } } -impl + ?Sized> HistoryBufferInner { +impl + ?Sized> HistoryBufInner { /// Clears the buffer pub fn clear(&mut self) { // SAFETY: we reset the values just after @@ -320,7 +321,7 @@ impl + ?Sized> HistoryBufferInner { } } -impl + ?Sized> HistoryBufferInner { +impl + ?Sized> HistoryBufInner { unsafe fn drop_contents(&mut self) { unsafe { ptr::drop_in_place(ptr::slice_from_raw_parts_mut( @@ -345,9 +346,9 @@ impl + ?Sized> HistoryBufferInner { /// # Examples /// /// ``` - /// use heapless::HistoryBuffer; + /// use heapless::HistoryBuf; /// - /// let x: HistoryBuffer = HistoryBuffer::new(); + /// let x: HistoryBuf = HistoryBuf::new(); /// assert!(x.is_empty()); /// ``` #[inline] @@ -401,9 +402,9 @@ impl + ?Sized> HistoryBufferInner { /// # Examples /// /// ``` - /// use heapless::HistoryBuffer; + /// use heapless::HistoryBuf; /// - /// let mut x: HistoryBuffer = HistoryBuffer::new(); + /// let mut x: HistoryBuf = HistoryBuf::new(); /// x.write(4); /// x.write(10); /// assert_eq!(x.recent(), Some(&10)); @@ -418,9 +419,9 @@ impl + ?Sized> HistoryBufferInner { /// # Examples /// /// ``` - /// use heapless::HistoryBuffer; + /// use heapless::HistoryBuf; /// - /// let mut x: HistoryBuffer = HistoryBuffer::new(); + /// let mut x: HistoryBuf = HistoryBuf::new(); /// x.write(4); /// x.write(10); /// assert_eq!(x.recent_index(), Some(1)); @@ -442,9 +443,9 @@ impl + ?Sized> HistoryBufferInner { /// # Examples /// /// ``` - /// use heapless::HistoryBuffer; + /// use heapless::HistoryBuf; /// - /// let mut x: HistoryBuffer = HistoryBuffer::new(); + /// let mut x: HistoryBuf = HistoryBuf::new(); /// x.write(4); /// x.write(10); /// assert_eq!(x.oldest(), Some(&4)); @@ -459,9 +460,9 @@ impl + ?Sized> HistoryBufferInner { /// # Examples /// /// ``` - /// use heapless::HistoryBuffer; + /// use heapless::HistoryBuf; /// - /// let mut x: HistoryBuffer = HistoryBuffer::new(); + /// let mut x: HistoryBuf = HistoryBuf::new(); /// x.write(4); /// x.write(10); /// assert_eq!(x.oldest_index(), Some(0)); @@ -487,9 +488,9 @@ impl + ?Sized> HistoryBufferInner { /// # Examples /// /// ``` - /// use heapless::HistoryBuffer; + /// use heapless::HistoryBuf; /// - /// let mut buffer: HistoryBuffer = HistoryBuffer::new(); + /// let mut buffer: HistoryBuf = HistoryBuf::new(); /// buffer.extend([0, 0, 0]); /// buffer.extend([1, 2, 3, 4, 5, 6]); /// assert_eq!(buffer.as_slices(), (&[1, 2, 3][..], &[4, 5, 6][..])); @@ -510,9 +511,9 @@ impl + ?Sized> HistoryBufferInner { /// # Examples /// /// ``` - /// use heapless::HistoryBuffer; + /// use heapless::HistoryBuf; /// - /// let mut buffer: HistoryBuffer = HistoryBuffer::new(); + /// let mut buffer: HistoryBuf = HistoryBuf::new(); /// buffer.extend([0, 0, 0, 1, 2, 3, 4, 5, 6]); /// let expected = [1, 2, 3, 4, 5, 6]; /// for (x, y) in buffer.oldest_ordered().zip(expected.iter()) { @@ -528,7 +529,7 @@ impl + ?Sized> HistoryBufferInner { } } -impl + ?Sized> Extend for HistoryBufferInner { +impl + ?Sized> Extend for HistoryBufInner { fn extend(&mut self, iter: I) where I: IntoIterator, @@ -539,7 +540,7 @@ impl + ?Sized> Extend for HistoryBufferInner { } } -impl<'a, T, S: HistBufStorage + ?Sized> Extend<&'a T> for HistoryBufferInner +impl<'a, T, S: HistoryBufStorage + ?Sized> Extend<&'a T> for HistoryBufInner where T: 'a + Clone, { @@ -551,7 +552,7 @@ where } } -impl Clone for HistoryBuffer +impl Clone for HistoryBuf where T: Clone, { @@ -566,13 +567,13 @@ where } } -impl + ?Sized> Drop for HistoryBufferInner { +impl + ?Sized> Drop for HistoryBufInner { fn drop(&mut self) { unsafe { self.drop_contents() } } } -impl + ?Sized> Deref for HistoryBufferInner { +impl + ?Sized> Deref for HistoryBufInner { type Target = [T]; fn deref(&self) -> &[T] { @@ -580,14 +581,14 @@ impl + ?Sized> Deref for HistoryBufferInner { } } -impl + ?Sized> AsRef<[T]> for HistoryBufferInner { +impl + ?Sized> AsRef<[T]> for HistoryBufInner { #[inline] fn as_ref(&self) -> &[T] { self } } -impl + ?Sized> fmt::Debug for HistoryBufferInner +impl + ?Sized> fmt::Debug for HistoryBufInner where T: fmt::Debug, { @@ -596,13 +597,13 @@ where } } -impl Default for HistoryBuffer { +impl Default for HistoryBuf { fn default() -> Self { Self::new() } } -impl + ?Sized> PartialEq for HistoryBufferInner +impl + ?Sized> PartialEq for HistoryBufInner where T: PartialEq, { @@ -611,11 +612,11 @@ where } } -/// Base struct for [`OldestOrdered`] and [`OldestOrderedView`], generic over the [`HistBufStorage`]. +/// Base struct for [`OldestOrdered`] and [`OldestOrderedView`], generic over the [`HistoryBufStorage`]. /// /// In most cases you should use [`OldestOrdered`] or [`OldestOrderedView`] directly. Only use this /// struct if you want to write code that's generic over both. -pub struct OldestOrderedInner<'a, T, S: HistBufStorage + ?Sized> { +pub struct OldestOrderedInner<'a, T, S: HistoryBufStorage + ?Sized> { phantom: PhantomData, inner: core::iter::Chain, core::slice::Iter<'a, T>>, } @@ -625,11 +626,11 @@ pub struct OldestOrderedInner<'a, T, S: HistBufStorage + ?Sized> { /// /// This type exists for backwards compatibility. It is always better to convert it to an [`OldestOrderedView`] with [`into_view`](OldestOrdered::into_view) pub type OldestOrdered<'a, T, const N: usize> = - OldestOrderedInner<'a, T, OwnedHistBufStorage>; + OldestOrderedInner<'a, T, OwnedHistoryBufStorage>; /// Double ended iterator on the underlying buffer ordered from the oldest data /// to the newest -pub type OldestOrderedView<'a, T> = OldestOrderedInner<'a, T, ViewHistBufStorage>; +pub type OldestOrderedView<'a, T> = OldestOrderedInner<'a, T, ViewHistoryBufStorage>; impl<'a, T, const N: usize> OldestOrdered<'a, T, N> { /// Remove the `N` const-generic parameter from the iterator @@ -657,7 +658,7 @@ impl<'a, T> OldestOrderedView<'a, T> { } } -impl + ?Sized> Clone for OldestOrderedInner<'_, T, S> { +impl + ?Sized> Clone for OldestOrderedInner<'_, T, S> { fn clone(&self) -> Self { Self { phantom: PhantomData, @@ -666,7 +667,7 @@ impl + ?Sized> Clone for OldestOrderedInner<'_, T, S> { } } -impl<'a, T, S: HistBufStorage + ?Sized> Iterator for OldestOrderedInner<'a, T, S> { +impl<'a, T, S: HistoryBufStorage + ?Sized> Iterator for OldestOrderedInner<'a, T, S> { type Item = &'a T; fn next(&mut self) -> Option<&'a T> { @@ -691,27 +692,27 @@ mod tests { use static_assertions::assert_not_impl_any; - use super::{HistoryBuffer, HistoryBufferView}; + use super::{HistoryBuf, HistoryBufView}; - // Ensure a `HistoryBuffer` containing `!Send` values stays `!Send` itself. - assert_not_impl_any!(HistoryBuffer<*const (), 4>: Send); + // Ensure a `HistoryBuf` containing `!Send` values stays `!Send` itself. + assert_not_impl_any!(HistoryBuf<*const (), 4>: Send); #[test] fn new() { - let x: HistoryBuffer = HistoryBuffer::new_with(1); + let x: HistoryBuf = HistoryBuf::new_with(1); assert_eq!(x.len(), 4); assert_eq!(x.as_slice(), [1; 4]); assert_eq!(*x, [1; 4]); assert!(x.is_full()); - let x: HistoryBuffer = HistoryBuffer::new(); + let x: HistoryBuf = HistoryBuf::new(); assert_eq!(x.as_slice(), []); assert!(!x.is_full()); } #[test] fn write() { - let mut x: HistoryBuffer = HistoryBuffer::new(); + let mut x: HistoryBuf = HistoryBuf::new(); x.write(1); x.write(4); assert_eq!(x.as_slice(), [1, 4]); @@ -727,18 +728,18 @@ mod tests { #[test] fn clear() { - let mut x: HistoryBuffer = HistoryBuffer::new_with(1); + let mut x: HistoryBuf = HistoryBuf::new_with(1); x.clear(); assert_eq!(x.as_slice(), []); - let mut x: HistoryBuffer = HistoryBuffer::new(); + let mut x: HistoryBuf = HistoryBuf::new(); x.clear_with(1); assert_eq!(x.as_slice(), [1; 4]); } #[test] fn clone() { - let mut x: HistoryBuffer = HistoryBuffer::new(); + let mut x: HistoryBuf = HistoryBuf::new(); for i in 0..10 { assert_eq!(x.as_slice(), x.clone().as_slice()); x.write(i); @@ -756,7 +757,7 @@ mod tests { } } - let mut y: HistoryBuffer = HistoryBuffer::new(); + let mut y: HistoryBuf = HistoryBuf::new(); let _ = y.clone(); assert_eq!(GLOBAL.load(Ordering::Relaxed), 0); y.write(InstrumentedClone(0)); @@ -779,7 +780,7 @@ mod tests { #[test] fn recent() { - let mut x: HistoryBuffer = HistoryBuffer::new(); + let mut x: HistoryBuf = HistoryBuf::new(); assert_eq!(x.recent_index(), None); assert_eq!(x.recent(), None); @@ -797,7 +798,7 @@ mod tests { #[test] fn oldest() { - let mut x: HistoryBuffer = HistoryBuffer::new(); + let mut x: HistoryBuf = HistoryBuf::new(); assert_eq!(x.oldest_index(), None); assert_eq!(x.oldest(), None); @@ -815,7 +816,7 @@ mod tests { #[test] fn as_slice() { - let mut x: HistoryBuffer = HistoryBuffer::new(); + let mut x: HistoryBuf = HistoryBuf::new(); assert_eq!(x.as_slice(), []); @@ -827,7 +828,7 @@ mod tests { /// Test whether `.as_slices()` behaves as expected. #[test] fn as_slices() { - let mut buffer: HistoryBuffer = HistoryBuffer::new(); + let mut buffer: HistoryBuf = HistoryBuf::new(); let mut extend_then_assert = |extend: &[u8], assert: (&[u8], &[u8])| { buffer.extend(extend); assert_eq!(buffer.as_slices(), assert); @@ -843,7 +844,7 @@ mod tests { /// Test whether `.as_slices()` and `.oldest_ordered()` produce elements in the same order. #[test] fn as_slices_equals_ordered() { - let mut buffer: HistoryBuffer = HistoryBuffer::new(); + let mut buffer: HistoryBuf = HistoryBuf::new(); for n in 0..20 { buffer.write(n); @@ -858,7 +859,7 @@ mod tests { #[test] fn ordered() { // test on an empty buffer - let buffer: HistoryBuffer = HistoryBuffer::new(); + let buffer: HistoryBuf = HistoryBuf::new(); let mut iter = buffer.oldest_ordered(); assert_eq!(iter.next(), None); assert_eq!(iter.next(), None); @@ -866,7 +867,7 @@ mod tests { assert_eq!(iter.next_back(), None); // test on a un-filled buffer - let mut buffer: HistoryBuffer = HistoryBuffer::new(); + let mut buffer: HistoryBuf = HistoryBuf::new(); buffer.extend([1, 2, 3]); assert_eq!(buffer.len(), 3); assert_eq_iter(buffer.oldest_ordered(), &[1, 2, 3]); @@ -879,14 +880,14 @@ mod tests { assert_eq!(iter.next(), None); // test on an exactly filled buffer - let mut buffer: HistoryBuffer = HistoryBuffer::new(); + let mut buffer: HistoryBuf = HistoryBuf::new(); buffer.extend([1, 2, 3, 4, 5, 6]); assert_eq!(buffer.len(), 6); assert_eq_iter(buffer.oldest_ordered(), &[1, 2, 3, 4, 5, 6]); assert_eq_iter(buffer.oldest_ordered().rev(), &[6, 5, 4, 3, 2, 1]); // test on a filled buffer - let mut buffer: HistoryBuffer = HistoryBuffer::new(); + let mut buffer: HistoryBuf = HistoryBuf::new(); buffer.extend([0, 0, 0, 1, 2, 3, 4, 5, 6]); assert_eq!(buffer.len(), 6); assert_eq_iter(buffer.oldest_ordered(), &[1, 2, 3, 4, 5, 6]); @@ -895,7 +896,7 @@ mod tests { // comprehensive test all cases for n in 0..50 { const N: usize = 7; - let mut buffer: HistoryBuffer = HistoryBuffer::new(); + let mut buffer: HistoryBuf = HistoryBuf::new(); buffer.extend(0..n); assert_eq_iter( buffer.oldest_ordered().copied(), @@ -933,8 +934,8 @@ mod tests { #[test] fn partial_eq() { - let mut x: HistoryBuffer = HistoryBuffer::new(); - let mut y: HistoryBuffer = HistoryBuffer::new(); + let mut x: HistoryBuf = HistoryBuf::new(); + let mut y: HistoryBuf = HistoryBuf::new(); assert_eq!(x, y); x.write(1); assert_ne!(x, y); @@ -969,7 +970,7 @@ mod tests { } } - let mut x: HistoryBuffer = HistoryBuffer::new(); + let mut x: HistoryBuf = HistoryBuf::new(); x.write(DropCheck {}); x.write(DropCheck {}); x.write(DropCheck {}); @@ -979,12 +980,12 @@ mod tests { assert_eq!(DROP_COUNT.load(Ordering::SeqCst), 3); } - fn _test_variance<'a: 'b, 'b>(x: HistoryBuffer<&'a (), 42>) -> HistoryBuffer<&'b (), 42> { + fn _test_variance<'a: 'b, 'b>(x: HistoryBuf<&'a (), 42>) -> HistoryBuf<&'b (), 42> { x } fn _test_variance_view<'a: 'b, 'b, 'c>( - x: &'c HistoryBufferView<&'a ()>, - ) -> &'c HistoryBufferView<&'b ()> { + x: &'c HistoryBufView<&'a ()>, + ) -> &'c HistoryBufView<&'b ()> { x } } diff --git a/src/lib.rs b/src/lib.rs index a818c9be..c8fe2899 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,7 +113,7 @@ )] //! - [`BinaryHeap`] -- priority queue //! - [Deque] -- double-ended queue -//! - [`HistoryBuffer`] -- similar to a write-only ring buffer +//! - [`HistoryBuf`] -- similar to a write-only ring buffer //! - [`IndexMap`] -- hash table //! - [`IndexSet`] -- hash set //! - [`LinearMap`] @@ -158,7 +158,7 @@ extern crate alloc; pub use binary_heap::BinaryHeap; pub use deque::Deque; -pub use histbuf::{HistoryBuffer, OldestOrdered}; +pub use history_buf::{HistoryBuf, OldestOrdered}; pub use index_map::IndexMap; pub use index_set::IndexSet; pub use len_type::LenType; @@ -172,7 +172,7 @@ pub use vec::{Vec, VecView}; mod test_helpers; pub mod deque; -pub mod histbuf; +pub mod history_buf; pub mod index_map; pub mod index_set; mod len_type; diff --git a/src/ser.rs b/src/ser.rs index 402cbfbf..4fd65e5e 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -3,7 +3,7 @@ use core::hash::{BuildHasher, Hash}; use crate::{ binary_heap::{BinaryHeapInner, Kind as BinaryHeapKind}, deque::DequeInner, - histbuf::{HistBufStorage, HistoryBufferInner}, + history_buf::{HistoryBufInner, HistoryBufStorage}, len_type::LenType, linear_map::{LinearMapInner, LinearMapStorage}, string::{StringInner, StringStorage}, @@ -81,7 +81,7 @@ where } } -impl + ?Sized> Serialize for HistoryBufferInner +impl + ?Sized> Serialize for HistoryBufInner where T: Serialize, { diff --git a/tests/cpass.rs b/tests/cpass.rs index efe1a3b0..28a85347 100644 --- a/tests/cpass.rs +++ b/tests/cpass.rs @@ -1,9 +1,9 @@ //! Collections of `Send`-able things are `Send` use heapless::{ - histbuf::HistoryBufferView, + history_buf::HistoryBufView, spsc::{Consumer, ConsumerView, Producer, ProducerView, Queue, QueueView}, - HistoryBuffer, Vec, VecView, + HistoryBuf, Vec, VecView, }; #[test] @@ -26,6 +26,6 @@ fn send() { is_send::>(); is_send::>(); is_send::>(); - is_send::>(); - is_send::>(); + is_send::>(); + is_send::>(); }