Struct nb_sync::fifo::Channel [−][src]
pub struct Channel<'a, T: 'a> { /* fields omitted */ }
Non-blocking FIFO
Alone, calling the recv
and send
methods on the channel requires that the caller guarantee
that those functions won't be called reentrantly. In order to remove this restriction, the
split
function can be called to split out the channel into a separate Sender
and Receiver
who use &mut self
to guarantee non-reentrancy.
Methods
impl<'a, T: 'a> Channel<'a, T>
[src]
impl<'a, T: 'a> Channel<'a, T>
pub fn new(buffer: &'a mut [Option<T>]) -> Self
[src]
pub fn new(buffer: &'a mut [Option<T>]) -> Self
Creates a new channel
The passed buffer will be borrowed for the lifetime of this channel and will serve as the shared storage between the sender and receiver.
To aid in optimization, the length of the slice should be a power of 2. But it doesn't have to be.
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Returns the length of the channel buffer
Note that the actual number of items that can be pending in the channel is 1 less than this value.
pub fn recv(&self, _nr: &NonReentrant) -> Result<T, !>
[src]
pub fn recv(&self, _nr: &NonReentrant) -> Result<T, !>
Receives from the channel
This returns a T
if successful, otherwise it returns a WouldBlock
. It is only
unsuccessful if the Channel is empty.
This requires a guarantee by the caller that this function will not be called reentrantly.
pub fn send(&self, value: T, nr: &NonReentrant) -> Result<(), !>
[src]
pub fn send(&self, value: T, nr: &NonReentrant) -> Result<(), !>
Sends a value to the channel
This returns a Ok(())
if successful, otherwise it returns a WouldBlock
. It is only
unsuccessful if the Channel is full.
This requires a guarantee by the caller that this function will not be called reentrantly.
pub fn send_lossless(
&self,
value: T,
_nr: &NonReentrant
) -> (Result<(), !>, Option<T>)
[src]
pub fn send_lossless(
&self,
value: T,
_nr: &NonReentrant
) -> (Result<(), !>, Option<T>)
Sends a value to the channel, preserving the passed value if unsuccessful
This returns a (Ok(()), None)
if successful, otherwise it returns a WouldBlock
with the Option
set
to the passed value. It is only unsuccessful if the Channel is full.
This requires a guarantee by the caller that this function will not be called reentrantly.
impl<'a, 'b: 'a, T: 'b> Channel<'b, T>
[src]
impl<'a, 'b: 'a, T: 'b> Channel<'b, T>
pub fn split(&'a mut self) -> (Receiver<'a, 'b, T>, Sender<'a, 'b, T>)
[src]
pub fn split(&'a mut self) -> (Receiver<'a, 'b, T>, Sender<'a, 'b, T>)
Builds a sender and receiver for this channel
The mutable borrow of self in this function will be for as long as the lifetimes of the receiver and sender. This ensures that the Channel stays in one place in memory and can't be split again while the sender and receiver are doing their thing.
The sender and receiver are not clonable. Due to this property they remove the requirement
for the caller to provide a NonReentrant
to the send
and recv
functions.
Trait Implementations
impl<'a, T: Debug + 'a> Debug for Channel<'a, T>
[src]
impl<'a, T: Debug + 'a> Debug for Channel<'a, T>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'a, T: 'a> Sync for Channel<'a, T>
[src]
impl<'a, T: 'a> Sync for Channel<'a, T>