mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
util/ringbuffer: Implement indexing
This commit is contained in:
@@ -71,6 +71,20 @@ impl<T: Eq + PartialEq + Clone, const N: usize> RingBuffer<T, N> {
|
||||
pub fn to_vec(&self) -> Vec<T> {
|
||||
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<T, const N: usize> std::ops::Index<usize> for RingBuffer<T, N> {
|
||||
type Output = T;
|
||||
|
||||
#[inline]
|
||||
fn index(&self, index: usize) -> &T {
|
||||
self.0.get(index).expect("Out of bounds access")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user