1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2017 Thomas de Zeeuw
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT
// or http://opensource.org/licenses/MIT>, at your option. This file may not be
// used, copied, modified, or distributed except according to those terms.
//! Optimized channels for Rust. This crate contains verious version of the same
//! concept, channels. The available versions are:
//!
//! - oneshot, allows a single value to be send and received.
//! - mpsc, allows for multiple producers (senders) and a single consumer
//! (receiver).
//!
//! All these different versions work in the same way. All modules will have a
//! `channel` function which returns a `Sender` and a `Receiver`. The `Sender`
//! can only send values and the `Receiver` can only receive values. The remaing
//! API are errors, which are a bit more channel version specific, and adapters
//! for the `futures` crate, see [below](#futures).
//!
//! # Example
//!
//! We'll use the oneshot channel for this example, but all versions will have
//! roughly the same type and structure setup.
//!
//! ```
//! # extern crate tchannel;
//! # fn main() {
//! use tchannel::oneshot::{channel, Sender, Receiver, ReceiveError};
//!
//! // Create a new channel, which has a sender and a receiver.
//! let (sender, receiver): (Sender<_>, Receiver<_>) = channel();
//!
//! // First we'll try to receive a value, but the channel should be empty so
//! // it will return an error. We can recover the receiver (`try_receive`
//! // consumes `Receiver` in case of an oneshot channel) via the `Empty` error.
//! let receiver = match receiver.try_receive() {
//! Err(ReceiveError::Empty(receiver)) => receiver,
//! _ => panic!("expected the channel to be empty"),
//! };
//!
//! // Now we'll send our value along the channel. In case of a oneshot channel
//! // this will consume the `Sender`.
//! //
//! // This will only return an error if the receiving side of the channel is
//! // disconnected, in which case it will return a `SendError` which allows
//! // the send value to retrieved.
//! assert_eq!(sender.send("Hello world"), Ok(()));
//!
//! // Here we'll receive the value, making sure it's the same as what we send.
//! assert_eq!(receiver.try_receive().unwrap(), "Hello world");
//! # }
//! ```
//!
//! # Futures
//!
//! Support for the [`futures`] crate is available if the `with-futures` feature
//! is enabled (disabled by default).
//!
//! TODO: add example usage.
//!
//! [`futures`]: https://crates.io/crates/futures
extern crate futures;
/// This error will be returned if the receiving side of the channel is
/// disconnected, while trying to send a value across the channel.
;
/// The error returned by trying to receive a value.