Struct rotating_buffer::RotatingBuffer [−][src]
pub struct RotatingBuffer<T: Default + Copy, const S: usize> { pub inner: [T; S], // some fields omitted }
Fields
inner: [T; S]
Implementations
Extracts slice with the length of the buffer’s internally tracked size
Example
let mut buf = RotatingBuffer::<u128, 20>::new(); assert_eq!(buf.as_slice().len(), 0); buf.add_len(15); assert_eq!(buf.as_slice().len(), 15);
Returns a mutable slice with the length of the currently “unused” allocation of the buffer
Example
let mut buf = RotatingBuffer::<u8, 5>::new(); buf.add_len(3); assert_eq!(buf.get_append_only().len(), 2); buf.get_append_only()[0] = 50; assert_eq!(buf.inner, [0, 0, 0, 50, 0]);
Manually set the internal size of the buffer
Panics
Panics if the new size is bigger than its capacity
Add to the current internal length of the buffer
Example
let mut buf = RotatingBuffer::<u8, 5>::new(); assert_eq!(buf.len(), 0); buf.add_len(3); assert_eq!(buf.len(), 3); buf.add_len(1); assert_eq!(buf.len(), 4);
Rotates the buffer contents in place (see core::slice::rotate_right
) and subsequently
changes the buffer’s internal length to however much was rotated
Example
let mut buf = RotatingBuffer::<bool, 5>::new(); buf.get_append_only()[3] = true; buf.add_len(5); buf.rotate_right_and_resize(2); assert_eq!(buf.as_slice()[0], true); assert_eq!(buf.len(), 2);
Rotate and resize buffer by supplying an index rather than a length
Example
let mut buf = RotatingBuffer::<bool, 5>::new(); buf.get_append_only()[3] = true; buf.add_len(5); buf.rotate_right_and_resize_at(3); assert_eq!(buf.as_slice()[0], true); assert_eq!(buf.len(), 2);
Trait Implementations
Maybe just to allow RotatingBuffer<RotatingBuffer<T, S>, S>
😄
Example
let mut buf = RotatingBuffer::<RotatingBuffer<u8, 10>, 5>::new(); buf.add_len(2); let slice = buf.as_slice(); assert_eq!(slice[0].inner, slice[1].inner);
But why!
Auto Trait Implementations
impl<T, const S: usize> Send for RotatingBuffer<T, S> where
T: Send,
impl<T, const S: usize> Sync for RotatingBuffer<T, S> where
T: Sync,
impl<T, const S: usize> Unpin for RotatingBuffer<T, S> where
T: Unpin,