From 70ff5360348b477c6f0c4ac857bdf792c4db74eb Mon Sep 17 00:00:00 2001 From: parazyd Date: Thu, 31 Aug 2023 17:49:31 +0200 Subject: [PATCH] util/ringbuffer: Implement indexing --- src/util/ringbuffer.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/util/ringbuffer.rs b/src/util/ringbuffer.rs index c571b37fd..2b76fb056 100644 --- a/src/util/ringbuffer.rs +++ b/src/util/ringbuffer.rs @@ -71,6 +71,20 @@ impl RingBuffer { pub fn to_vec(&self) -> Vec { self.0.iter().cloned().collect() } + + /// Rearranges the internal storage of this deque so it is one contiguous slice. + pub fn make_contiguous(&mut self) -> &mut [T] { + self.0.make_contiguous() + } +} + +impl std::ops::Index for RingBuffer { + type Output = T; + + #[inline] + fn index(&self, index: usize) -> &T { + self.0.get(index).expect("Out of bounds access") + } } #[cfg(test)]