diff --git a/src/lib.rs b/src/lib.rs index 6a53ba3..4199a50 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,7 +38,6 @@ //! ``` #![warn(rust_2018_idioms)] -#![warn(single_use_lifetimes)] #![deny(missing_docs)] use std::cell::Cell; @@ -225,6 +224,29 @@ impl Drop for RingBuffer { } } +impl PartialEq for RingBuffer { + /// This method tests for `self` and `other` values to be equal, and is used by `==`. + /// + /// # Examples + /// + /// ``` + /// use rtrb::RingBuffer; + /// + /// let (p, c) = RingBuffer::::new(1000).split(); + /// assert_eq!(p.buffer, c.buffer); + /// + /// let rb1 = RingBuffer::::new(1000); + /// let rb2 = RingBuffer::::new(1000); + /// assert_ne!(rb1, rb2); + /// ``` + fn eq(&self, other: &Self) -> bool { + // There can never be multiple instances with the same `data_ptr`. + std::ptr::eq(self.data_ptr, other.data_ptr) + } +} + +impl Eq for RingBuffer {} + /// The producer side of a [`RingBuffer`]. /// /// Can be moved between threads, @@ -466,7 +488,7 @@ impl Producer { /// /// let (producer, consumer) = RingBuffer::::new(1000).split(); /// ``` -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub struct Consumer { /// A read-only reference to the ring buffer. pub buffer: Arc>, @@ -981,7 +1003,7 @@ impl<'a, T> Iterator for WriteChunkMaybeUninit<'a, T> { /// If desired, this has to be explicitly done by calling [`commit()`](ReadChunk::commit), /// [`commit_iterated()`](ReadChunk::commit_iterated) or [`commit_all()`](ReadChunk::commit_all). /// Note that this runs the destructor of the committed items (if `T` implements [`Drop`]). -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub struct ReadChunk<'a, T> { first_ptr: *const T, first_len: usize,