Expand description

Bounded capacity channel.

The channel is a multi-producer, single-consumer (MPSC) bounded queue. It is designed to be used as inbox for actors, following the actor model.


The implementation assumes the access to the channel is mostly uncontested and optimises for this use case. Furthermore it optimises for small memory footprint, sometimes over faster access.

The implementation doesn’t provide a lot of guarantees. For example this channel is not guaranteed to be First In First Out (FIFO), it does this on a best effort basis. In return it means that a slow Sender does not block the receiving of other messages.


Simple creation of a channel and sending a message over it.

 use std::thread;

 use heph_inbox::RecvError;

 // Create a new small channel.
 let (sender, mut receiver) = heph_inbox::new_small();

 let sender_handle = thread::spawn(move || {
     if let Err(err) = sender.try_send("Hello world!".to_owned()) {
         panic!("Failed to send value: {}", err);

 let receiver_handle = thread::spawn(move || {
     // NOTE: this is just an example don't actually use a loop like this, it
     // will waste CPU cycles when the channel is empty!
     loop {
         match receiver.try_recv() {
             Ok(value) => println!("Got a value: {}", value),
             Err(RecvError::Empty) => continue,
             Err(RecvError::Disconnected) => break,



One-shot channel.


Identifier of a channel.

Future implementation behind Sender::join.

Manager of a channel.

Future implementation behind Receiver::peek.

Receiving side of the channel.

Error returned by Manager::new_receiver if a receiver is already connected.

Future implementation behind Receiver::recv.

Future implementation behind Sender::send.

Sending side of the channel.


Error returned in case receiving a value from the channel fails. See Receiver::try_recv.

Error returned in case sending a value across the channel fails. See Sender::try_send.


Maximum capacity of a channel.

Minimum capacity of a channel.


Create a new bounded channel.

Create a small bounded channel.