blob: 22d90d8a63a895c213a8f15ce5baf51c0990ed0e [file] [log] [blame]
Jason Macnak09c36882020-04-01 16:22:56 +00001//! Asynchronous channels.
2//!
Haibo Huang09da6032021-02-09 17:02:02 -08003//! Like threads, concurrent tasks sometimes need to communicate with each
4//! other. This module contains two basic abstractions for doing so:
Jason Macnak09c36882020-04-01 16:22:56 +00005//!
Haibo Huang09da6032021-02-09 17:02:02 -08006//! - [oneshot], a way of sending a single value from one task to another.
7//! - [mpsc], a multi-producer, single-consumer channel for sending values
8//! between tasks, analogous to the similarly-named structure in the standard
9//! library.
10//!
11//! All items are only available when the `std` or `alloc` feature of this
Jason Macnak09c36882020-04-01 16:22:56 +000012//! library is activated, and it is activated by default.
13
14#![cfg_attr(feature = "cfg-target-has-atomic", feature(cfg_target_has_atomic))]
15
16#![cfg_attr(not(feature = "std"), no_std)]
17
18#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms, unreachable_pub)]
19// It cannot be included in the published code because this lints have false positives in the minimum required version.
20#![cfg_attr(test, warn(single_use_lifetimes))]
21#![warn(clippy::all)]
Jason Macnak09c36882020-04-01 16:22:56 +000022#![doc(test(attr(deny(warnings), allow(dead_code, unused_assignments, unused_variables))))]
23
Jason Macnak09c36882020-04-01 16:22:56 +000024#[cfg(all(feature = "cfg-target-has-atomic", not(feature = "unstable")))]
25compile_error!("The `cfg-target-has-atomic` feature requires the `unstable` feature as an explicit opt-in to unstable features");
26
27macro_rules! cfg_target_has_atomic {
28 ($($item:item)*) => {$(
29 #[cfg_attr(feature = "cfg-target-has-atomic", cfg(target_has_atomic = "ptr"))]
30 $item
31 )*};
32}
33
34cfg_target_has_atomic! {
35 #[cfg(feature = "alloc")]
36 extern crate alloc;
37
38 #[cfg(feature = "alloc")]
39 mod lock;
40 #[cfg(feature = "std")]
41 pub mod mpsc;
42 #[cfg(feature = "alloc")]
43 pub mod oneshot;
44}