pub struct CircularBuffer<const N: usize, T> { /* private fields */ }
Expand description

A fixed-size circular buffer.

A CircularBuffer may live on the stack. Wrap the CircularBuffer in a Box using CircularBuffer::boxed() if you need the struct to be heap-allocated.

See the module-level documentation for more details and examples.

Implementations§

source§

impl<const N: usize, T> CircularBuffer<N, T>

source

pub const fn new() -> Self

Returns an empty CircularBuffer.

Examples
use circular_buffer::CircularBuffer;
let buf = CircularBuffer::<16, u32>::new();
assert_eq!(buf, []);
source

pub fn boxed() -> Box<Self>

Returns an empty heap-allocated CircularBuffer.

Examples
use circular_buffer::CircularBuffer;
let buf = CircularBuffer::<1024, f64>::boxed();
assert_eq!(buf.len(), 0);
source

pub const fn len(&self) -> usize

Returns the number of elements in the buffer.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<16, u32>::new();
assert_eq!(buf.len(), 0);

buf.push_back(1);
buf.push_back(2);
buf.push_back(3);
assert_eq!(buf.len(), 3);
source

pub const fn capacity(&self) -> usize

Returns the capacity of the buffer.

This is the maximum number of elements that the buffer can hold.

This method always returns the generic const parameter N.

Examples
use circular_buffer::CircularBuffer;
let mut buf = CircularBuffer::<16, u32>::new();
assert_eq!(buf.capacity(), 16);
source

pub const fn is_empty(&self) -> bool

Returns true if the buffer contains 0 elements.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<16, u32>::new();
assert!(buf.is_empty());

buf.push_back(1);
assert!(!buf.is_empty());
source

pub const fn is_full(&self) -> bool

Returns true if the number of elements in the buffer matches the buffer capacity.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<5, u32>::new();
assert!(!buf.is_full());

buf.push_back(1);
assert!(!buf.is_full());

buf.push_back(2);
buf.push_back(3);
buf.push_back(4);
buf.push_back(5);
assert!(buf.is_full());
source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the elements of the buffer.

The iterator advances from front to back. Use .rev() to advance from back to front.

Examples

Iterate from front to back:

use circular_buffer::CircularBuffer;

let buf = CircularBuffer::<5, char>::from_iter("abc".chars());
let mut it = buf.iter();

assert_eq!(it.next(), Some(&'a'));
assert_eq!(it.next(), Some(&'b'));
assert_eq!(it.next(), Some(&'c'));
assert_eq!(it.next(), None);

Iterate from back to front:

use circular_buffer::CircularBuffer;

let buf = CircularBuffer::<5, char>::from_iter("abc".chars());
let mut it = buf.iter().rev();

assert_eq!(it.next(), Some(&'c'));
assert_eq!(it.next(), Some(&'b'));
assert_eq!(it.next(), Some(&'a'));
assert_eq!(it.next(), None);
source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator over the elements of the buffer that allows modifying each value.

The iterator advances from front to back. Use .rev() to advance from back to front.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<5, u32>::from([1, 2, 3]);
for elem in buf.iter_mut() {
    *elem += 5;
}
assert_eq!(buf, [6, 7, 8]);
source

pub fn range<R>(&self, range: R) -> Iter<'_, T> where R: RangeBounds<usize>,

Returns an iterator over the specified range of elements of the buffer.

The iterator advances from front to back. Use .rev() to advance from back to front.

Panics

If the start of the range is greater than the end, or if the end is greater than the length of the buffer.

Examples

Iterate from front to back:

use circular_buffer::CircularBuffer;

let buf = CircularBuffer::<16, char>::from_iter("abcdefghi".chars());
let mut it = buf.range(3..6);

assert_eq!(it.next(), Some(&'d'));
assert_eq!(it.next(), Some(&'e'));
assert_eq!(it.next(), Some(&'f'));
assert_eq!(it.next(), None);

Iterate from back to front:

use circular_buffer::CircularBuffer;

let buf = CircularBuffer::<16, char>::from_iter("abcdefghi".chars());
let mut it = buf.range(3..6).rev();

assert_eq!(it.next(), Some(&'f'));
assert_eq!(it.next(), Some(&'e'));
assert_eq!(it.next(), Some(&'d'));
assert_eq!(it.next(), None);
source

pub fn range_mut<R>(&mut self, range: R) -> IterMut<'_, T> where R: RangeBounds<usize>,

Returns an iterator over the specified range of elements of the buffer that allows modifying each value.

The iterator advances from front to back. Use .rev() to advance from back to front.

Panics

If the start of the range is greater than the end, or if the end is greater than the length of the buffer.

Examples

Iterate from front to back:

use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<16, i32>::from_iter([1, 2, 3, 4, 5, 6]);
for elem in buf.range_mut(..3) {
    *elem *= -1;
}
assert_eq!(buf, [-1, -2, -3, 4, 5, 6]);
source

pub fn as_slices(&self) -> (&[T], &[T])

Returns a pair of slices which contain the elements of this buffer.

The second slice may be empty if the internal buffer is contiguous.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<4, char>::new();
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
buf.push_back('d');

// Buffer is contiguous; second slice is empty
assert_eq!(buf.as_slices(), (&['a', 'b', 'c', 'd'][..], &[][..]));

buf.push_back('e');
buf.push_back('f');

// Buffer is disjoint; both slices are non-empty
assert_eq!(buf.as_slices(), (&['c', 'd'][..], &['e', 'f'][..]));
source

pub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])

Returns a pair of mutable slices which contain the elements of this buffer.

These slices can be used to modify or replace the elements in the buffer.

The second slice may be empty if the internal buffer is contiguous.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<4, char>::new();
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
buf.push_back('d');
buf.push_back('e');
buf.push_back('f');

assert_eq!(buf, ['c', 'd', 'e', 'f']);

let (left, right) = buf.as_mut_slices();
assert_eq!(left, &mut ['c', 'd'][..]);
assert_eq!(right, &mut ['e', 'f'][..]);

left[0] = 'z';

assert_eq!(buf, ['z', 'd', 'e', 'f']);
source

pub fn back(&self) -> Option<&T>

Returns a reference to the back element, or None if the buffer is empty.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<4, char>::new();
assert_eq!(buf.back(), None);

buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
assert_eq!(buf.back(), Some(&'c'));
source

pub fn back_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the back element, or None if the buffer is empty.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<4, char>::new();
assert_eq!(buf.back_mut(), None);

buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
match buf.back_mut() {
    None => (),
    Some(x) => *x = 'z',
}
assert_eq!(buf, ['a', 'b', 'z']);
source

pub fn front(&self) -> Option<&T>

Returns a reference to the front element, or None if the buffer is empty.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<4, char>::new();
assert_eq!(buf.front(), None);

buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
assert_eq!(buf.front(), Some(&'a'));
source

pub fn front_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the front element, or None if the buffer is empty.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<4, char>::new();
assert_eq!(buf.front_mut(), None);

buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
match buf.front_mut() {
    None => (),
    Some(x) => *x = 'z',
}
assert_eq!(buf, ['z', 'b', 'c']);
source

pub fn get(&self, index: usize) -> Option<&T>

Returns a reference to the element at the given index, or None if the element does not exist.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<4, char>::new();
assert_eq!(buf.get(1), None);

buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
assert_eq!(buf.get(1), Some(&'b'));
source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Returns a mutable reference to the element at the given index, or None if the element does not exist.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<4, char>::new();
assert_eq!(buf.get_mut(1), None);

buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
match buf.get_mut(1) {
    None => (),
    Some(x) => *x = 'z',
}
assert_eq!(buf, ['a', 'z', 'c']);
source

pub fn push_back(&mut self, item: T)

Appends an element to the back of the buffer.

If the buffer is full, the element at the front of the buffer is automatically dropped.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<3, char>::new();

buf.push_back('a'); assert_eq!(buf, ['a']);
buf.push_back('b'); assert_eq!(buf, ['a', 'b']);
buf.push_back('c'); assert_eq!(buf, ['a', 'b', 'c']);
// The buffer is now full; adding more values causes the front elements to be dropped
buf.push_back('d'); assert_eq!(buf, ['b', 'c', 'd']);
buf.push_back('e'); assert_eq!(buf, ['c', 'd', 'e']);
buf.push_back('f'); assert_eq!(buf, ['d', 'e', 'f']);
source

pub fn push_front(&mut self, item: T)

Appends an element to the front of the buffer.

If the buffer is full, the element at the back of the buffer is automatically dropped.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<3, char>::new();

buf.push_front('a'); assert_eq!(buf, ['a']);
buf.push_front('b'); assert_eq!(buf, ['b', 'a']);
buf.push_front('c'); assert_eq!(buf, ['c', 'b', 'a']);
// The buffer is now full; adding more values causes the back elements to be dropped
buf.push_front('d'); assert_eq!(buf, ['d', 'c', 'b']);
buf.push_front('e'); assert_eq!(buf, ['e', 'd', 'c']);
buf.push_front('f'); assert_eq!(buf, ['f', 'e', 'd']);
source

pub fn pop_back(&mut self) -> Option<T>

Removes and returns an element from the back of the buffer.

If the buffer is empty, None is returned.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<3, char>::from(['a', 'b', 'c']);

assert_eq!(buf.pop_back(), Some('c'));
assert_eq!(buf.pop_back(), Some('b'));
assert_eq!(buf.pop_back(), Some('a'));
assert_eq!(buf.pop_back(), None);
source

pub fn pop_front(&mut self) -> Option<T>

Removes and returns an element from the front of the buffer.

If the buffer is empty, None is returned.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<3, char>::from(['a', 'b', 'c']);

assert_eq!(buf.pop_front(), Some('a'));
assert_eq!(buf.pop_front(), Some('b'));
assert_eq!(buf.pop_front(), Some('c'));
assert_eq!(buf.pop_front(), None);
source

pub fn remove(&mut self, index: usize) -> Option<T>

Removes and returns an element at the specified index.

If the index is out of bounds, None is returned.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<3, char>::from(['a', 'b', 'c']);

assert_eq!(buf.remove(1), Some('b'));
assert_eq!(buf, ['a', 'c']);

assert_eq!(buf.remove(5), None);
source

pub fn swap(&mut self, i: usize, j: usize)

Swap the element at index i with the element at index j.

Panics

If either i or j is out of bounds.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<5, char>::from(['a', 'b', 'c', 'd']);
assert_eq!(buf, ['a', 'b', 'c', 'd']);

buf.swap(0, 3);
assert_eq!(buf, ['d', 'b', 'c', 'a']);

Trying to swap an invalid index panics:

use circular_buffer::CircularBuffer;
let mut buf = CircularBuffer::<5, char>::from(['a', 'b', 'c', 'd']);
buf.swap(0, 7);
source

pub fn swap_remove_back(&mut self, index: usize) -> Option<T>

Removes the element at index and returns it, replacing it with the back of the buffer.

Returns None if index is out-of-bounds.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<5, char>::from(['a', 'b', 'c', 'd']);
assert_eq!(buf, ['a', 'b', 'c', 'd']);

assert_eq!(buf.swap_remove_back(2), Some('c'));
assert_eq!(buf, ['a', 'b', 'd']);

assert_eq!(buf.swap_remove_back(7), None);
source

pub fn swap_remove_front(&mut self, index: usize) -> Option<T>

Removes the element at index and returns it, replacing it with the front of the buffer.

Returns None if index is out-of-bounds.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<5, char>::from(['a', 'b', 'c', 'd']);
assert_eq!(buf, ['a', 'b', 'c', 'd']);

assert_eq!(buf.swap_remove_front(2), Some('c'));
assert_eq!(buf, ['b', 'a', 'd']);

assert_eq!(buf.swap_remove_front(7), None);
source

pub fn truncate_back(&mut self, len: usize)

Shortens the buffer, keeping only the front len elements and dropping the rest.

If len is equal or greater to the buffer’s current length, this has no effect.

Calling truncate_back(0) is equivalent to clear().

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<4, u32>::from([10, 20, 30]);

buf.truncate_back(1);
assert_eq!(buf, [10]);

// Truncating to a length that is greater than the buffer's length has no effect
buf.truncate_back(8);
assert_eq!(buf, [10]);
source

pub fn truncate_front(&mut self, len: usize)

Shortens the buffer, keeping only the back len elements and dropping the rest.

If len is equal or greater to the buffer’s current length, this has no effect.

Calling truncate_front(0) is equivalent to clear().

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<4, u32>::from([10, 20, 30]);

buf.truncate_front(1);
assert_eq!(buf, [30]);

// Truncating to a length that is greater than the buffer's length has no effect
buf.truncate_front(8);
assert_eq!(buf, [30]);
source

pub fn clear(&mut self)

Drops all the elements in the buffer.

Examples
use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<4, u32>::from([10, 20, 30]);
assert_eq!(buf, [10, 20, 30]);
buf.clear();
assert_eq!(buf, []);
source§

impl<const N: usize, T> CircularBuffer<N, T>where T: Clone,

source

pub fn extend_from_slice(&mut self, other: &[T])

Clones and appends all the elements from the slice to the back of the buffer.

This is an optimized version of extend() for slices.

If slice contains more values than the available capacity, the elements at the front of the buffer are dropped.

Examples
use circular_buffer::CircularBuffer;

let mut buf: CircularBuffer<5, u32> = CircularBuffer::from([1, 2, 3]);
buf.extend_from_slice(&[4, 5, 6, 7]);
assert_eq!(buf, [3, 4, 5, 6, 7]);
source

pub fn to_vec(&self) -> Vec<T>

Clones the elements of the buffer into a new Vec, leaving the buffer unchanged.

Examples
use circular_buffer::CircularBuffer;

let buf: CircularBuffer<5, u32> = CircularBuffer::from([1, 2, 3]);
let vec: Vec<u32> = buf.to_vec();

assert_eq!(buf, [1, 2, 3]);
assert_eq!(vec, [1, 2, 3]);

Trait Implementations§

source§

impl<const N: usize, T> Clone for CircularBuffer<N, T>where T: Clone,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
source§

fn clone_from(&mut self, other: &Self)

Performs copy-assignment from source. Read more
source§

impl<const N: usize, T> Debug for CircularBuffer<N, T>where T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const N: usize, T> Default for CircularBuffer<N, T>

source§

fn default() -> Self

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

impl<const N: usize, T> Drop for CircularBuffer<N, T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, const N: usize, T> Extend<&'a T> for CircularBuffer<N, T>where T: Copy,

source§

fn extend<I>(&mut self, iter: I)where I: IntoIterator<Item = &'a T>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<const N: usize, T> Extend<T> for CircularBuffer<N, T>

source§

fn extend<I>(&mut self, iter: I)where I: IntoIterator<Item = T>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<const N: usize, const M: usize, T> From<[T; M]> for CircularBuffer<N, T>

source§

fn from(arr: [T; M]) -> Self

Converts to this type from the input type.
source§

impl<const N: usize, T> FromIterator<T> for CircularBuffer<N, T>

source§

fn from_iter<I>(iter: I) -> Selfwhere I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
source§

impl<const N: usize, T> Hash for CircularBuffer<N, T>where T: Hash,

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, const N: usize, T> IntoIterator for &'a CircularBuffer<N, T>

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<const N: usize, T> IntoIterator for CircularBuffer<N, T>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<N, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<const N: usize, T> Ord for CircularBuffer<N, T>where T: Ord,

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<'a, const N: usize, T, U> PartialEq<&'a [U]> for CircularBuffer<N, T>where T: PartialEq<U>,

source§

fn eq(&self, other: &&'a [U]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, const N: usize, const M: usize, T, U> PartialEq<&'a [U; M]> for CircularBuffer<N, T>where T: PartialEq<U>,

source§

fn eq(&self, other: &&'a [U; M]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, const N: usize, T, U> PartialEq<&'a mut [U]> for CircularBuffer<N, T>where T: PartialEq<U>,

source§

fn eq(&self, other: &&'a mut [U]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, const N: usize, const M: usize, T, U> PartialEq<&'a mut [U; M]> for CircularBuffer<N, T>where T: PartialEq<U>,

source§

fn eq(&self, other: &&'a mut [U; M]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const N: usize, T, U> PartialEq<[U]> for CircularBuffer<N, T>where T: PartialEq<U>,

source§

fn eq(&self, other: &[U]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const N: usize, const M: usize, T, U> PartialEq<[U; M]> for CircularBuffer<N, T>where T: PartialEq<U>,

source§

fn eq(&self, other: &[U; M]) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const N: usize, const M: usize, T, U> PartialEq<CircularBuffer<M, U>> for CircularBuffer<N, T>where T: PartialEq<U>,

source§

fn eq(&self, other: &CircularBuffer<M, U>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const N: usize, const M: usize, T, U> PartialOrd<CircularBuffer<M, U>> for CircularBuffer<N, T>where T: PartialOrd<U>,

source§

fn partial_cmp(&self, other: &CircularBuffer<M, U>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<const N: usize> Read for CircularBuffer<N, u8>

source§

fn read(&mut self, dst: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · source§

fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>

Read all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Read all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Read the exact number of bytes required to fill buf. Read more
source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · source§

fn bytes(self) -> Bytes<Self>where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · source§

fn chain<R>(self, next: R) -> Chain<Self, R>where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · source§

fn take(self, limit: u64) -> Take<Self>where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
source§

impl<const N: usize> Write for CircularBuffer<N, u8>

source§

fn write(&mut self, src: &[u8]) -> Result<usize>

Write a buffer into this writer, returning how many bytes were written. Read more
source§

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · source§

fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more
source§

impl<const N: usize, T> Eq for CircularBuffer<N, T>where T: Eq,

Auto Trait Implementations§

§

impl<const N: usize, T> RefUnwindSafe for CircularBuffer<N, T>where T: RefUnwindSafe,

§

impl<const N: usize, T> Send for CircularBuffer<N, T>where T: Send,

§

impl<const N: usize, T> Sync for CircularBuffer<N, T>where T: Sync,

§

impl<const N: usize, T> Unpin for CircularBuffer<N, T>where T: Unpin,

§

impl<const N: usize, T> UnwindSafe for CircularBuffer<N, T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.