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]

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.

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.

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.

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.

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]

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]

Formats the value using the given formatter. Read more

impl<'a, T: 'a> Sync for Channel<'a, T>
[src]

Auto Trait Implementations

impl<'a, T> Send for Channel<'a, T> where
    T: Send