pub struct HeapCircularBuffer<T> { /* private fields */ }Expand description
A heap-allocated, variable-size circular buffer.
A HeapCircularBuffer can be allocated at runtime with an arbitrary capacity, similar to a
Vec. The capacity of the buffer can be adjusted using resize().
See the module-level documentation for more details and examples.
Implementations§
Source§impl<T> HeapCircularBuffer<T>
impl<T> HeapCircularBuffer<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Returns an empty HeapCircularBuffer with the specified capacity.
§Examples
use circular_buffer::HeapCircularBuffer;
let buf = HeapCircularBuffer::<u32>::with_capacity(16);
assert_eq!(buf.capacity(), 16);
assert_eq!(buf.len(), 0);
assert_eq!(buf, []);Sourcepub fn resize(&mut self, new_capacity: usize)
pub fn resize(&mut self, new_capacity: usize)
Changes the capacity of the buffer, without changing its elements.
§Panics
If new_capacity is lower than the number of elements in the buffer.
§Examples
Increasing capacity:
use circular_buffer::HeapCircularBuffer;
let mut buf = HeapCircularBuffer::<char>::with_capacity(3);
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
buf.push_back('d');
assert_eq!(buf, ['b', 'c', 'd']);
buf.resize(5);
buf.push_back('e');
buf.push_back('f');
buf.push_back('g');
assert_eq!(buf, ['c', 'd', 'e', 'f', 'g']);Decreasing capacity is fine as long as the new capacity leaves enough room for existing elements:
use circular_buffer::HeapCircularBuffer;
let mut buf = HeapCircularBuffer::<char>::with_capacity(3);
assert_eq!(buf.capacity(), 3);
buf.push_back('a');
buf.push_back('b');
assert_eq!(buf, ['a', 'b']);
buf.resize(2);
assert_eq!(buf.capacity(), 2);
assert_eq!(buf, ['a', 'b']);Decreasing capacity panics if the buffer is too large:
use circular_buffer::HeapCircularBuffer;
let mut buf = HeapCircularBuffer::<char>::with_capacity(3);
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
buf.resize(2); // panicsSourcepub const fn as_circular_buffer(&self) -> &CircularBuffer<T>
pub const fn as_circular_buffer(&self) -> &CircularBuffer<T>
Returns a reference to this buffer.
Sourcepub const fn as_mut_circular_buffer(&mut self) -> &mut CircularBuffer<T>
pub const fn as_mut_circular_buffer(&mut self) -> &mut CircularBuffer<T>
Returns a mutable reference to this buffer.
Sourcepub fn leak<'a>(self) -> &'a mut CircularBuffer<T>where
T: 'a,
pub fn leak<'a>(self) -> &'a mut CircularBuffer<T>where
T: 'a,
Consumes and leaks the buffer, returning a mutable reference to the contents as a
CircularBuffer.
Note that the type T must outlive the chosen lifetime 'a. If the type has only static
references, or none at all, then this may be chosen to be 'static.
This function is mainly useful for data that lives for the remainder of the program’s life. Dropping the returned reference will cause a memory leak.
§Examples
use circular_buffer::CircularBuffer;
use circular_buffer::HeapCircularBuffer;
let mut buf = HeapCircularBuffer::<u32>::with_capacity(5);
buf.extend([1, 2, 3]);
let static_ref: &'static mut CircularBuffer<u32> = buf.leak();
assert_eq!(static_ref, [1, 2, 3]);
Sourcepub fn into_boxed_circular_buffer(self) -> Box<CircularBuffer<T>>
pub fn into_boxed_circular_buffer(self) -> Box<CircularBuffer<T>>
Converts the HeapCircularBuffer<T> into a Box<CircularBuffer<T>>.
§Examples
use circular_buffer::HeapCircularBuffer;
let mut buf = HeapCircularBuffer::<u32>::with_capacity(5);
buf.extend([1, 2, 3]);
let boxed_buf = buf.into_boxed_circular_buffer();
assert_eq!(&*boxed_buf, [1, 2, 3]);Methods from Deref<Target = CircularBuffer<T>>§
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the buffer.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 16>::new();
assert_eq!(buf.len(), 0);
buf.push_back(1);
buf.push_back(2);
buf.push_back(3);
assert_eq!(buf.len(), 3);Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the capacity of the buffer.
This is the maximum number of elements that the buffer can hold.
§Examples
use circular_buffer::FixedCircularBuffer;
let buf = FixedCircularBuffer::<u32, 16>::new();
assert_eq!(buf.capacity(), 16);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the buffer contains 0 elements.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 16>::new();
assert!(buf.is_empty());
buf.push_back(1);
assert!(!buf.is_empty());Sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Returns true if the number of elements in the buffer matches the buffer capacity.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 5>::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());Sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
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::FixedCircularBuffer;
let buf = FixedCircularBuffer::<char, 5>::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::FixedCircularBuffer;
let buf = FixedCircularBuffer::<char, 5>::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);Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 5>::from([1, 2, 3]);
for elem in buf.iter_mut() {
*elem += 5;
}
assert_eq!(buf, [6, 7, 8]);Sourcepub fn range<R>(&self, range: R) -> Iter<'_, T> ⓘwhere
R: RangeBounds<usize>,
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::FixedCircularBuffer;
let buf = FixedCircularBuffer::<char, 16>::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::FixedCircularBuffer;
let buf = FixedCircularBuffer::<char, 16>::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);Sourcepub fn range_mut<R>(&mut self, range: R) -> IterMut<'_, T> ⓘwhere
R: RangeBounds<usize>,
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<i32, 16>::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]);Sourcepub fn drain<R>(&mut self, range: R) -> Drain<'_, T> ⓘwhere
R: RangeBounds<usize>,
pub fn drain<R>(&mut self, range: R) -> Drain<'_, T> ⓘwhere
R: RangeBounds<usize>,
Removes the specified range from the buffer in bulk, returning the removed elements as an iterator. If the iterator is dropped before being fully consumed, it drops the remaining removed elements.
§Panics
If the start of the range is greater than the end, or if the end is greater than the length of the buffer.
§Leaking
If the returned iterator goes out of scope without being dropped (for example, due to
calling mem::forget() on it), the buffer may have lost and leaked arbitrary elements,
including elements outside of the range.
The current implementation leaks all the elements of the buffer if the iterator is leaked, but this behavior may change in the future.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 6>::from_iter("abcdef".chars());
let drained = buf.drain(3..).collect::<Vec<char>>();
assert_eq!(drained, ['d', 'e', 'f']);
assert_eq!(buf, ['a', 'b', 'c']);Not consuming the draining iterator still removes the range of elements:
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 6>::from_iter("abcdef".chars());
buf.drain(3..);
assert_eq!(buf, ['a', 'b', 'c']);Sourcepub fn make_contiguous(&mut self) -> &mut [T]
pub fn make_contiguous(&mut self) -> &mut [T]
Rearranges the internal memory of the buffer so that all elements are in a contiguous slice, which is then returned.
This method does not allocate and does not change the order of the inserted elements. Because it returns a mutable slice, any slice methods may be called on the elements of the buffer, such as sorting methods.
Once the internal storage is contiguous, the as_slices() and
as_mut_slices() methods will return the entire contents of the
deque in a single slice. Adding new elements to the buffer may make the buffer disjoint (not
contiguous).
§Complexity
If the buffer is disjoint (not contiguous), this method takes O(N) time, where N is the capacity of the buffer.
If the buffer is already contiguous, this method takes O(1) time.
This means that this method may be called multiple times on the same buffer without a performance penalty (provided that no new elements are added to the buffer in between calls).
§Examples
use circular_buffer::FixedCircularBuffer;
// Create a new buffer, adding more elements than its capacity
let mut buf = FixedCircularBuffer::<u32, 4>::from_iter([1, 4, 3, 0, 2, 5]);
assert_eq!(buf, [3, 0, 2, 5]);
// The buffer is disjoint: as_slices() returns two non-empty slices
assert_eq!(buf.as_slices(), (&[3, 0][..], &[2, 5][..]));
// Make the buffer contiguous
assert_eq!(buf.make_contiguous(), &mut [3, 0, 2, 5]);
// as_slices() now returns a single non-empty slice
assert_eq!(buf.as_slices(), (&[3, 0, 2, 5][..], &[][..]));
// The order of the elements in the buffer did not get modified
assert_eq!(buf, [3, 0, 2, 5]);
// Make the buffer contiguous and sort its elements
buf.make_contiguous().sort();
assert_eq!(buf, [0, 2, 3, 5]);Sourcepub fn as_slices(&self) -> (&[T], &[T])
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 4>::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'][..]));Sourcepub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 4>::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']);Sourcepub fn back(&self) -> Option<&T>
pub fn back(&self) -> Option<&T>
Returns a reference to the back element, or None if the buffer is empty.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 4>::new();
assert_eq!(buf.back(), None);
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
assert_eq!(buf.back(), Some(&'c'));Sourcepub fn back_mut(&mut self) -> Option<&mut T>
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 4>::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']);Sourcepub fn front(&self) -> Option<&T>
pub fn front(&self) -> Option<&T>
Returns a reference to the front element, or None if the buffer is empty.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 4>::new();
assert_eq!(buf.front(), None);
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
assert_eq!(buf.front(), Some(&'a'));Sourcepub fn front_mut(&mut self) -> Option<&mut T>
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 4>::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']);Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Returns a reference to the element at the given index from the front of the buffer, or
None if the element does not exist.
Element at index 0 is the front of the queue.
This is the same as nth_front().
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 5>::new();
assert_eq!(buf.get(1), None);
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
buf.push_back('d');
assert_eq!(buf.get(1), Some(&'b'));Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
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.
Element at index 0 is the front of the queue.
This is the same as nth_front_mut().
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 5>::new();
assert_eq!(buf.get_mut(1), None);
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
buf.push_back('d');
match buf.get_mut(1) {
None => (),
Some(x) => *x = 'z',
}
assert_eq!(buf, ['a', 'z', 'c', 'd']);Sourcepub fn nth_front(&self, index: usize) -> Option<&T>
pub fn nth_front(&self, index: usize) -> Option<&T>
Returns a reference to the element at the given index from the front of the buffer, or
None if the element does not exist.
Like most indexing operations, the count starts from zero, so nth_front(0) returns the
first value, nth_front(1) the second, and so on. Element at index 0 is the front of the
queue.
This is the same as get().
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 5>::new();
assert_eq!(buf.nth_front(1), None);
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
buf.push_back('d');
assert_eq!(buf.nth_front(1), Some(&'b'));Sourcepub fn nth_front_mut(&mut self, index: usize) -> Option<&mut T>
pub fn nth_front_mut(&mut self, index: usize) -> Option<&mut T>
Returns a mutable reference to the element at the given index from the front of the buffer,
or None if the element does not exist.
Like most indexing operations, the count starts from zero, so nth_front_mut(0) returns
the first value, nth_front_mut(1) the second, and so on. Element at index 0 is the front
of the queue.
This is the same as get_mut().
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 5>::new();
assert_eq!(buf.nth_front_mut(1), None);
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
buf.push_back('d');
match buf.nth_front_mut(1) {
None => (),
Some(x) => *x = 'z',
}
assert_eq!(buf, ['a', 'z', 'c', 'd']);Sourcepub fn nth_back(&self, index: usize) -> Option<&T>
pub fn nth_back(&self, index: usize) -> Option<&T>
Returns a reference to the element at the given index from the back of the buffer, or
None if the element does not exist.
Like most indexing operations, the count starts from zero, so nth_back(0) returns the
first value, nth_back(1) the second, and so on. Element at index 0 is the back of the
queue.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 5>::new();
assert_eq!(buf.nth_back(1), None);
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
buf.push_back('d');
assert_eq!(buf.nth_back(1), Some(&'c'));Sourcepub fn nth_back_mut(&mut self, index: usize) -> Option<&mut T>
pub fn nth_back_mut(&mut self, index: usize) -> Option<&mut T>
Returns a mutable reference to the element at the given index from the back of the buffer,
or None if the element does not exist.
Like most indexing operations, the count starts from zero, so nth_back_mut(0) returns the
first value, nth_back_mut(1) the second, and so on. Element at index 0 is the back of the
queue.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 5>::new();
assert_eq!(buf.nth_back_mut(1), None);
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
buf.push_back('d');
match buf.nth_back_mut(1) {
None => (),
Some(x) => *x = 'z',
}
assert_eq!(buf, ['a', 'b', 'z', 'd']);Sourcepub fn push_back(&mut self, item: T) -> Option<T>
pub fn push_back(&mut self, item: T) -> Option<T>
Appends an element to the back of the buffer.
If the buffer is full, the element at the front of the buffer is overwritten and returned.
See also try_push_back() for a non-overwriting version of this
method.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 3>::new();
assert_eq!(buf.push_back('a'), None);
assert_eq!(buf, ['a']);
assert_eq!(buf.push_back('b'), None);
assert_eq!(buf, ['a', 'b']);
assert_eq!(buf.push_back('c'), None);
assert_eq!(buf, ['a', 'b', 'c']);
// The buffer is now full; adding more values causes the front elements to be removed and
// returned
assert_eq!(buf.push_back('d'), Some('a'));
assert_eq!(buf, ['b', 'c', 'd']);
assert_eq!(buf.push_back('e'), Some('b'));
assert_eq!(buf, ['c', 'd', 'e']);
assert_eq!(buf.push_back('f'), Some('c'));
assert_eq!(buf, ['d', 'e', 'f']);Sourcepub fn try_push_back(&mut self, item: T) -> Result<(), T>
pub fn try_push_back(&mut self, item: T) -> Result<(), T>
Appends an element to the back of the buffer.
If the buffer is full, the buffer is not modified and the given element is returned as an error.
See also push_back() for a version of this method that overwrites the
front of the buffer when full.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 3>::new();
assert_eq!(buf.try_push_back('a'), Ok(()));
assert_eq!(buf, ['a']);
assert_eq!(buf.try_push_back('b'), Ok(()));
assert_eq!(buf, ['a', 'b']);
assert_eq!(buf.try_push_back('c'), Ok(()));
assert_eq!(buf, ['a', 'b', 'c']);
// The buffer is now full; adding more values results in an error
assert_eq!(buf.try_push_back('d'), Err('d'))Sourcepub fn push_front(&mut self, item: T) -> Option<T>
pub fn push_front(&mut self, item: T) -> Option<T>
Appends an element to the front of the buffer.
If the buffer is full, the element at the back of the buffer is overwritten and returned.
See also try_push_front() for a non-overwriting version of this
method.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 3>::new();
assert_eq!(buf.push_front('a'), None);
assert_eq!(buf, ['a']);
assert_eq!(buf.push_front('b'), None);
assert_eq!(buf, ['b', 'a']);
assert_eq!(buf.push_front('c'), None);
assert_eq!(buf, ['c', 'b', 'a']);
// The buffer is now full; adding more values causes the back elements to be dropped
assert_eq!(buf.push_front('d'), Some('a'));
assert_eq!(buf, ['d', 'c', 'b']);
assert_eq!(buf.push_front('e'), Some('b'));
assert_eq!(buf, ['e', 'd', 'c']);
assert_eq!(buf.push_front('f'), Some('c'));
assert_eq!(buf, ['f', 'e', 'd']);Sourcepub fn try_push_front(&mut self, item: T) -> Result<(), T>
pub fn try_push_front(&mut self, item: T) -> Result<(), T>
Appends an element to the front of the buffer.
If the buffer is full, the buffer is not modified and the given element is returned as an error.
See also push_front() for a version of this method that overwrites the
back of the buffer when full.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 3>::new();
assert_eq!(buf.try_push_front('a'), Ok(()));
assert_eq!(buf, ['a']);
assert_eq!(buf.try_push_front('b'), Ok(()));
assert_eq!(buf, ['b', 'a']);
assert_eq!(buf.try_push_front('c'), Ok(()));
assert_eq!(buf, ['c', 'b', 'a']);
// The buffer is now full; adding more values results in an error
assert_eq!(buf.try_push_front('d'), Err('d'));Sourcepub fn pop_back(&mut self) -> Option<T>
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 3>::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);Sourcepub fn pop_front(&mut self) -> Option<T>
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 3>::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);Sourcepub fn remove(&mut self, index: usize) -> Option<T>
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 3>::from(['a', 'b', 'c']);
assert_eq!(buf.remove(1), Some('b'));
assert_eq!(buf, ['a', 'c']);
assert_eq!(buf.remove(5), None);Sourcepub fn swap(&mut self, i: usize, j: usize)
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 5>::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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 5>::from(['a', 'b', 'c', 'd']);
buf.swap(0, 7);Sourcepub fn swap_remove_back(&mut self, index: usize) -> Option<T>
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 5>::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);Sourcepub fn swap_remove_front(&mut self, index: usize) -> Option<T>
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<char, 5>::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);Sourcepub fn fill(&mut self, value: T)where
T: Clone,
pub fn fill(&mut self, value: T)where
T: Clone,
Fills the entire capacity of self with elements by cloning value.
The elements already present in the buffer (if any) are all replaced by clones of value,
and the spare capacity of the buffer is also filled with clones of value.
This is equivalent to clearing the buffer and adding clones of value until reaching the
maximum capacity.
If you want to replace only the existing elements of the buffer, without affecting the spare
capacity, use as_mut_slices() and call slice::fill() on the
resulting slices.
See also: fill_with(), fill_spare(),
fill_spare_with().
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 10>::from([1, 2, 3]);
assert_eq!(buf, [1, 2, 3]);
buf.fill(9);
assert_eq!(buf, [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]);If you want to replace existing elements only:
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 10>::from([1, 2, 3]);
assert_eq!(buf, [1, 2, 3]);
let (front, back) = buf.as_mut_slices();
front.fill(9);
back.fill(9);
assert_eq!(buf, [9, 9, 9]);Sourcepub fn fill_with<F>(&mut self, f: F)where
F: FnMut() -> T,
pub fn fill_with<F>(&mut self, f: F)where
F: FnMut() -> T,
Fills the entire capacity of self with elements by calling a closure.
The elements already present in the buffer (if any) are all replaced by the result of the closure, and the spare capacity of the buffer is also filled with the result of the closure.
This is equivalent to clearing the buffer and adding the result of the closure until reaching the maximum capacity.
If you want to replace only the existing elements of the buffer, without affecting the spare
capacity, use as_mut_slices() and call slice::fill_with() on
the resulting slices.
See also: fill(), fill_spare(),
fill_spare_with().
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 10>::from([1, 2, 3]);
assert_eq!(buf, [1, 2, 3]);
let mut x = 2;
buf.fill_with(|| {
x *= 2;
x
});
assert_eq!(buf, [4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048]);If you want to replace existing elements only:
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 10>::from([1, 2, 3]);
assert_eq!(buf, [1, 2, 3]);
let mut x = 2;
let (front, back) = buf.as_mut_slices();
front.fill_with(|| {
x *= 2;
x
});
back.fill_with(|| {
x *= 2;
x
});
assert_eq!(buf, [4, 8, 16]);Sourcepub fn fill_spare(&mut self, value: T)where
T: Clone,
pub fn fill_spare(&mut self, value: T)where
T: Clone,
Fills the spare capacity of self with elements by cloning value.
The elements already present in the buffer (if any) are unaffected.
This is equivalent to adding clones of value to the buffer until reaching the maximum
capacity.
See also: fill(), fill_with(),
fill_spare_with().
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 10>::from([1, 2, 3]);
assert_eq!(buf, [1, 2, 3]);
buf.fill_spare(9);
assert_eq!(buf, [1, 2, 3, 9, 9, 9, 9, 9, 9, 9]);Sourcepub fn fill_spare_with<F>(&mut self, f: F)where
F: FnMut() -> T,
pub fn fill_spare_with<F>(&mut self, f: F)where
F: FnMut() -> T,
Fills the spare capacity of self with elements by calling a closure.
The elements already present in the buffer (if any) are unaffected.
This is equivalent to adding the result of the closure to the buffer until reaching the maximum capacity.
See also: fill(), fill_with(),
fill_spare().
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 10>::from([1, 2, 3]);
assert_eq!(buf, [1, 2, 3]);
let mut x = 2;
buf.fill_spare_with(|| {
x *= 2;
x
});
assert_eq!(buf, [1, 2, 3, 4, 8, 16, 32, 64, 128, 256]);Sourcepub fn truncate_back(&mut self, len: usize)
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 4>::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]);Sourcepub fn truncate_front(&mut self, len: usize)
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::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 4>::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]);Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drops all the elements in the buffer.
§Examples
use circular_buffer::FixedCircularBuffer;
let mut buf = FixedCircularBuffer::<u32, 4>::from([10, 20, 30]);
assert_eq!(buf, [10, 20, 30]);
buf.clear();
assert_eq!(buf, []);Sourcepub fn extend_from_slice(&mut self, other: &[T])
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::FixedCircularBuffer;
let mut buf: FixedCircularBuffer<u32, 5> = FixedCircularBuffer::from([1, 2, 3]);
buf.extend_from_slice(&[4, 5, 6, 7]);
assert_eq!(buf, [3, 4, 5, 6, 7]);Trait Implementations§
Source§impl<T> AsMut<CircularBuffer<T>> for HeapCircularBuffer<T>
impl<T> AsMut<CircularBuffer<T>> for HeapCircularBuffer<T>
Source§fn as_mut(&mut self) -> &mut CircularBuffer<T>
fn as_mut(&mut self) -> &mut CircularBuffer<T>
Source§impl<T> AsRef<CircularBuffer<T>> for HeapCircularBuffer<T>
impl<T> AsRef<CircularBuffer<T>> for HeapCircularBuffer<T>
Source§fn as_ref(&self) -> &CircularBuffer<T>
fn as_ref(&self) -> &CircularBuffer<T>
Source§impl<T> Borrow<CircularBuffer<T>> for HeapCircularBuffer<T>
impl<T> Borrow<CircularBuffer<T>> for HeapCircularBuffer<T>
Source§fn borrow(&self) -> &CircularBuffer<T>
fn borrow(&self) -> &CircularBuffer<T>
Source§impl<T> BorrowMut<CircularBuffer<T>> for HeapCircularBuffer<T>
impl<T> BorrowMut<CircularBuffer<T>> for HeapCircularBuffer<T>
Source§fn borrow_mut(&mut self) -> &mut CircularBuffer<T>
fn borrow_mut(&mut self) -> &mut CircularBuffer<T>
Source§impl BufRead for HeapCircularBuffer<u8>
Available on crate features alloc and embedded-io only.
impl BufRead for HeapCircularBuffer<u8>
alloc and embedded-io only.Source§impl BufRead for HeapCircularBuffer<u8>
Available on crate features alloc and embedded-io-async only.
impl BufRead for HeapCircularBuffer<u8>
alloc and embedded-io-async only.Source§impl BufRead for HeapCircularBuffer<u8>
impl BufRead for HeapCircularBuffer<u8>
Source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
Read methods, if empty. Read moreSource§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amount of additional bytes from the internal buffer as having been read.
Subsequent calls to read only return bytes that have not been marked as read. Read moreSource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left)read. Read more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
byte or EOF is reached. Read more1.0.0 · Source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
0xA byte) is reached, and append
them to the provided String buffer. Read moreSource§impl<T> Clone for HeapCircularBuffer<T>where
T: Clone,
impl<T> Clone for HeapCircularBuffer<T>where
T: Clone,
Source§impl<T> Debug for HeapCircularBuffer<T>where
T: Debug,
Available on crate feature alloc only.
impl<T> Debug for HeapCircularBuffer<T>where
T: Debug,
alloc only.Source§impl<T> Deref for HeapCircularBuffer<T>
impl<T> Deref for HeapCircularBuffer<T>
Source§impl<T> DerefMut for HeapCircularBuffer<T>
impl<T> DerefMut for HeapCircularBuffer<T>
Source§impl<T> Drop for HeapCircularBuffer<T>
impl<T> Drop for HeapCircularBuffer<T>
impl<T> Eq for HeapCircularBuffer<T>where
T: Eq,
alloc only.Source§impl ErrorType for HeapCircularBuffer<u8>
Available on crate feature alloc only.
impl ErrorType for HeapCircularBuffer<u8>
alloc only.Source§type Error = Infallible
type Error = Infallible
Source§impl<T> Hash for HeapCircularBuffer<T>where
T: Hash,
Available on crate feature alloc only.
impl<T> Hash for HeapCircularBuffer<T>where
T: Hash,
alloc only.Source§impl<T> Index<usize> for HeapCircularBuffer<T>
impl<T> Index<usize> for HeapCircularBuffer<T>
Source§impl<T> IndexMut<usize> for HeapCircularBuffer<T>
impl<T> IndexMut<usize> for HeapCircularBuffer<T>
Source§impl<T> IntoIterator for HeapCircularBuffer<T>
impl<T> IntoIterator for HeapCircularBuffer<T>
Source§impl<'a, T> IntoIterator for &'a HeapCircularBuffer<T>
impl<'a, T> IntoIterator for &'a HeapCircularBuffer<T>
Source§impl<'a, T> IntoIterator for &'a mut HeapCircularBuffer<T>
impl<'a, T> IntoIterator for &'a mut HeapCircularBuffer<T>
Source§impl<T> Ord for HeapCircularBuffer<T>where
T: Ord,
Available on crate feature alloc only.
impl<T> Ord for HeapCircularBuffer<T>where
T: Ord,
alloc only.1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T, U> PartialEq<&CircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<&CircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &&CircularBuffer<U>) -> bool
fn eq(&self, other: &&CircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<&HeapCircularBuffer<U>> for CircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<&HeapCircularBuffer<U>> for CircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &&HeapCircularBuffer<U>) -> bool
fn eq(&self, other: &&HeapCircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<&HeapCircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<&HeapCircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &&HeapCircularBuffer<U>) -> bool
fn eq(&self, other: &&HeapCircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U, const M: usize> PartialEq<&[U; M]> for HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U, const M: usize> PartialEq<&[U; M]> for HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§impl<T, U> PartialEq<&mut CircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<&mut CircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &&mut CircularBuffer<U>) -> bool
fn eq(&self, other: &&mut CircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<&mut HeapCircularBuffer<U>> for CircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<&mut HeapCircularBuffer<U>> for CircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &&mut HeapCircularBuffer<U>) -> bool
fn eq(&self, other: &&mut HeapCircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<&mut HeapCircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<&mut HeapCircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &&mut HeapCircularBuffer<U>) -> bool
fn eq(&self, other: &&mut HeapCircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U, const M: usize> PartialEq<&mut [U; M]> for HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U, const M: usize> PartialEq<&mut [U; M]> for HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§impl<T, U> PartialEq<CircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<CircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &CircularBuffer<U>) -> bool
fn eq(&self, other: &CircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<CircularBuffer<U>> for &HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<CircularBuffer<U>> for &HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &CircularBuffer<U>) -> bool
fn eq(&self, other: &CircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<CircularBuffer<U>> for &mut HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<CircularBuffer<U>> for &mut HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &CircularBuffer<U>) -> bool
fn eq(&self, other: &CircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<HeapCircularBuffer<U>> for CircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<HeapCircularBuffer<U>> for CircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<HeapCircularBuffer<U>> for &CircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<HeapCircularBuffer<U>> for &CircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<HeapCircularBuffer<U>> for &mut CircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<HeapCircularBuffer<U>> for &mut CircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<HeapCircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<HeapCircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<HeapCircularBuffer<U>> for &HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<HeapCircularBuffer<U>> for &HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U> PartialEq<HeapCircularBuffer<U>> for &mut HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U> PartialEq<HeapCircularBuffer<U>> for &mut HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
fn eq(&self, other: &HeapCircularBuffer<U>) -> bool
self and other values to be equal, and is used by ==.Source§impl<T, U, const M: usize> PartialEq<[U; M]> for &HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U, const M: usize> PartialEq<[U; M]> for &HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§impl<T, U, const M: usize> PartialEq<[U; M]> for &mut HeapCircularBuffer<T>where
T: PartialEq<U>,
impl<T, U, const M: usize> PartialEq<[U; M]> for &mut HeapCircularBuffer<T>where
T: PartialEq<U>,
Source§impl<T, U> PartialOrd<HeapCircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialOrd<U>,
Available on crate feature alloc only.
impl<T, U> PartialOrd<HeapCircularBuffer<U>> for HeapCircularBuffer<T>where
T: PartialOrd<U>,
alloc only.Source§impl Read for HeapCircularBuffer<u8>
Available on crate features alloc and embedded-io only.
impl Read for HeapCircularBuffer<u8>
alloc and embedded-io only.Source§fn read(&mut self, dst: &mut [u8]) -> Result<usize, Self::Error>
fn read(&mut self, dst: &mut [u8]) -> Result<usize, Self::Error>
Source§fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf. Read moreSource§impl Read for HeapCircularBuffer<u8>
Available on crate features alloc and embedded-io-async only.
impl Read for HeapCircularBuffer<u8>
alloc and embedded-io-async only.Source§async fn read(&mut self, dst: &mut [u8]) -> Result<usize, Self::Error>
async fn read(&mut self, dst: &mut [u8]) -> Result<usize, Self::Error>
Source§async fn read_exact(
&mut self,
buf: &mut [u8],
) -> Result<(), ReadExactError<Self::Error>>
async fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>
buf. Read moreSource§impl Read for HeapCircularBuffer<u8>
impl Read for HeapCircularBuffer<u8>
Source§fn read(&mut self, dst: &mut [u8]) -> Result<usize>
fn read(&mut self, dst: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_, u8>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(
&mut self,
cursor: BorrowedCursor<'_, u8>,
) -> Result<(), Error>
fn read_buf_exact( &mut self, cursor: BorrowedCursor<'_, u8>, ) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
1.0.0 · Source§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit bytes from it. Read moreSource§fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
fn read_array<const N: usize>(&mut self) -> Result<[u8; N], Error>where
Self: Sized,
read_array)Source§impl Write for HeapCircularBuffer<u8>
Available on crate features alloc and embedded-io only.
impl Write for HeapCircularBuffer<u8>
alloc and embedded-io only.Source§fn write(&mut self, src: &[u8]) -> Result<usize, Self::Error>
fn write(&mut self, src: &[u8]) -> Result<usize, Self::Error>
Source§fn flush(&mut self) -> Result<(), Self::Error>
fn flush(&mut self) -> Result<(), Self::Error>
Source§impl Write for HeapCircularBuffer<u8>
Available on crate features alloc and embedded-io-async only.
impl Write for HeapCircularBuffer<u8>
alloc and embedded-io-async only.Source§async fn flush(&mut self) -> Result<(), Self::Error>
async fn flush(&mut self) -> Result<(), Self::Error>
Source§impl Write for HeapCircularBuffer<u8>
impl Write for HeapCircularBuffer<u8>
Source§fn write(&mut self, src: &[u8]) -> Result<usize>
fn write(&mut self, src: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)