pub struct RingBuffer { /* private fields */ }
Expand description
Atomic reusable ringbuffer
This ringbuffer implementation is designed to be stored in a static
,
therefore all methods take &self
and not &mut self
.
It is “reusable”: when created it has no backing buffer, you can give it
one with init
and take it back with deinit
, and init it again in the
future if needed. This is very non-idiomatic, but helps a lot when storing
it in a static
.
One concurrent writer and one concurrent reader are supported, even at different execution priorities (like main and irq).
Implementations§
source§impl RingBuffer
impl RingBuffer
sourcepub unsafe fn init(&self, buf: *mut u8, len: usize)
pub unsafe fn init(&self, buf: *mut u8, len: usize)
Initialize the ring buffer with a buffer.
§Safety
- The buffer (
buf .. buf+len
) must be valid memory untildeinit
is called. - Must not be called concurrently with any other methods.
sourcepub unsafe fn deinit(&self)
pub unsafe fn deinit(&self)
Deinitialize the ringbuffer.
After calling this, the ringbuffer becomes empty, as if it was
just created with new()
.
§Safety
- Must not be called concurrently with any other methods.
sourcepub unsafe fn try_reader(&self) -> Option<Reader<'_>>
pub unsafe fn try_reader(&self) -> Option<Reader<'_>>
sourcepub unsafe fn try_writer(&self) -> Option<Writer<'_>>
pub unsafe fn try_writer(&self) -> Option<Writer<'_>>
sourcepub fn is_available(&self) -> bool
pub fn is_available(&self) -> bool
Return if buffer is available.
Auto Trait Implementations§
impl !Freeze for RingBuffer
impl RefUnwindSafe for RingBuffer
impl Send for RingBuffer
impl Sync for RingBuffer
impl Unpin for RingBuffer
impl UnwindSafe for RingBuffer
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more