소스 검색

util/ringbuffer: Implement back() method.

parazyd 3 년 전
부모
커밋
9102fbf33c
1개의 변경된 파일5개의 추가작업 그리고 0개의 파일을 삭제
  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)]