Skip to content

Commit 9220657

Browse files
committed
Implement PartialEq and Eq for main structs.
This causes a spurious single_use_lifetimes warning, see rust-lang/rust#53738
1 parent c66d052 commit 9220657

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/lib.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
//! ```
3939
4040
#![warn(rust_2018_idioms)]
41-
#![warn(single_use_lifetimes)]
4241
#![deny(missing_docs)]
4342

4443
use std::cell::Cell;
@@ -225,6 +224,29 @@ impl<T> Drop for RingBuffer<T> {
225224
}
226225
}
227226

227+
impl<T> PartialEq for RingBuffer<T> {
228+
/// This method tests for `self` and `other` values to be equal, and is used by `==`.
229+
///
230+
/// # Examples
231+
///
232+
/// ```
233+
/// use rtrb::RingBuffer;
234+
///
235+
/// let (p, c) = RingBuffer::<f32>::new(1000).split();
236+
/// assert_eq!(p.buffer, c.buffer);
237+
///
238+
/// let rb1 = RingBuffer::<f32>::new(1000);
239+
/// let rb2 = RingBuffer::<f32>::new(1000);
240+
/// assert_ne!(rb1, rb2);
241+
/// ```
242+
fn eq(&self, other: &Self) -> bool {
243+
// There can never be multiple instances with the same `data_ptr`.
244+
std::ptr::eq(self.data_ptr, other.data_ptr)
245+
}
246+
}
247+
248+
impl<T> Eq for RingBuffer<T> {}
249+
228250
/// The producer side of a [`RingBuffer`].
229251
///
230252
/// Can be moved between threads,
@@ -466,7 +488,7 @@ impl<T> Producer<T> {
466488
///
467489
/// let (producer, consumer) = RingBuffer::<f32>::new(1000).split();
468490
/// ```
469-
#[derive(Debug)]
491+
#[derive(Debug, PartialEq, Eq)]
470492
pub struct Consumer<T> {
471493
/// A read-only reference to the ring buffer.
472494
pub buffer: Arc<RingBuffer<T>>,
@@ -981,7 +1003,7 @@ impl<'a, T> Iterator for WriteChunkMaybeUninit<'a, T> {
9811003
/// If desired, this has to be explicitly done by calling [`commit()`](ReadChunk::commit),
9821004
/// [`commit_iterated()`](ReadChunk::commit_iterated) or [`commit_all()`](ReadChunk::commit_all).
9831005
/// Note that this runs the destructor of the committed items (if `T` implements [`Drop`]).
984-
#[derive(Debug)]
1006+
#[derive(Debug, PartialEq, Eq)]
9851007
pub struct ReadChunk<'a, T> {
9861008
first_ptr: *const T,
9871009
first_len: usize,

0 commit comments

Comments
 (0)