Browse Source

util/ringbuffer: Implement back() method.

parazyd 3 years ago
parent
commit
9102fbf33c
1 changed files with 5 additions and 0 deletions
  1. 5 0
      src/util/ringbuffer.rs

+ 5 - 0
src/util/ringbuffer.rs

@@ -64,6 +64,11 @@ impl<T: Eq + PartialEq + Clone> RingBuffer<T> {
     pub fn contains(&self, x: &T) -> bool {
         self.data.contains(x)
     }
+
+    /// Provides a reference to the back element, or `None` if empty.
+    pub fn back(&self) -> Option<&T> {
+        self.data.back()
+    }
 }
 
 #[cfg(test)]