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]);

Returns true if the buffer’s internal size is 0

Returns internally tracked length

Returns the capacity of this buffer

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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!

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.