|
38 | 38 | //! ```
|
39 | 39 |
|
40 | 40 | #![warn(rust_2018_idioms)]
|
41 |
| -#![warn(single_use_lifetimes)] |
42 | 41 | #![deny(missing_docs)]
|
43 | 42 |
|
44 | 43 | use std::cell::Cell;
|
@@ -225,6 +224,29 @@ impl<T> Drop for RingBuffer<T> {
|
225 | 224 | }
|
226 | 225 | }
|
227 | 226 |
|
| 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 | + |
228 | 250 | /// The producer side of a [`RingBuffer`].
|
229 | 251 | ///
|
230 | 252 | /// Can be moved between threads,
|
@@ -466,7 +488,7 @@ impl<T> Producer<T> {
|
466 | 488 | ///
|
467 | 489 | /// let (producer, consumer) = RingBuffer::<f32>::new(1000).split();
|
468 | 490 | /// ```
|
469 |
| -#[derive(Debug)] |
| 491 | +#[derive(Debug, PartialEq, Eq)] |
470 | 492 | pub struct Consumer<T> {
|
471 | 493 | /// A read-only reference to the ring buffer.
|
472 | 494 | pub buffer: Arc<RingBuffer<T>>,
|
@@ -981,7 +1003,7 @@ impl<'a, T> Iterator for WriteChunkMaybeUninit<'a, T> {
|
981 | 1003 | /// If desired, this has to be explicitly done by calling [`commit()`](ReadChunk::commit),
|
982 | 1004 | /// [`commit_iterated()`](ReadChunk::commit_iterated) or [`commit_all()`](ReadChunk::commit_all).
|
983 | 1005 | /// Note that this runs the destructor of the committed items (if `T` implements [`Drop`]).
|
984 |
| -#[derive(Debug)] |
| 1006 | +#[derive(Debug, PartialEq, Eq)] |
985 | 1007 | pub struct ReadChunk<'a, T> {
|
986 | 1008 | first_ptr: *const T,
|
987 | 1009 | first_len: usize,
|
|
0 commit comments