summaryrefslogtreecommitdiffstats
path: root/tokio/src/runtime/mod.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2019-11-18 07:00:55 -0800
committerGitHub <noreply@github.com>2019-11-18 07:00:55 -0800
commit0d38936b35779b604770120da2e98560bbb6241f (patch)
tree843d46e999becdb580cb02655b4290acadd64474 /tokio/src/runtime/mod.rs
parent13b6e9939e062dc01bcf34abe3d75de4b66e20e1 (diff)
chore: refine feature flags (#1785)
Removes dependencies between Tokio feature flags. For example, `process` should not depend on `sync` simply because it uses the `mpsc` channel. Instead, feature flags represent **public** APIs that become available with the feature enabled. When the feature is not enabled, the functionality is removed. If another Tokio component requires the functionality, it is stays as `pub(crate)`. The threaded scheduler is now exposed under `rt-threaded`. This feature flag only enables the threaded scheduler and does not include I/O, networking, or time. Those features must be explictly enabled. A `full` feature flag is added that enables all features. `stdin`, `stdout`, `stderr` are exposed under `io-std`. Macros are used to scope code by feature flag.
Diffstat (limited to 'tokio/src/runtime/mod.rs')
-rw-r--r--tokio/src/runtime/mod.rs39
1 files changed, 20 insertions, 19 deletions
diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs
index 8f66b725..a022f955 100644
--- a/tokio/src/runtime/mod.rs
+++ b/tokio/src/runtime/mod.rs
@@ -132,10 +132,10 @@
#[macro_use]
mod tests;
-#[cfg(feature = "rt-core")]
-mod basic_scheduler;
-#[cfg(feature = "rt-core")]
-use self::basic_scheduler::BasicScheduler;
+cfg_rt_core! {
+ mod basic_scheduler;
+ use basic_scheduler::BasicScheduler;
+}
mod blocking;
use blocking::BlockingPool;
@@ -146,10 +146,10 @@ pub use self::builder::Builder;
pub(crate) mod enter;
use self::enter::enter;
-#[cfg(feature = "rt-core")]
-mod global;
-#[cfg(feature = "rt-core")]
-pub(crate) use self::global::spawn;
+cfg_rt_core! {
+ mod global;
+ pub(crate) use global::spawn;
+}
mod handle;
pub use self::handle::Handle;
@@ -164,13 +164,14 @@ use self::shell::Shell;
mod time;
-#[cfg(feature = "rt-full")]
-pub(crate) mod thread_pool;
-#[cfg(feature = "rt-full")]
-use self::thread_pool::ThreadPool;
+cfg_rt_threaded! {
+ pub(crate) mod thread_pool;
+ use self::thread_pool::ThreadPool;
+}
-#[cfg(feature = "rt-core")]
-use crate::task::JoinHandle;
+cfg_rt_core! {
+ use crate::task::JoinHandle;
+}
use std::future::Future;
@@ -223,7 +224,7 @@ enum Kind {
Basic(BasicScheduler<time::Driver>),
/// Execute tasks across multiple threads.
- #[cfg(feature = "rt-full")]
+ #[cfg(feature = "rt-threaded")]
ThreadPool(ThreadPool),
}
@@ -254,10 +255,10 @@ impl Runtime {
///
/// [mod]: index.html
pub fn new() -> io::Result<Self> {
- #[cfg(feature = "rt-full")]
+ #[cfg(feature = "rt-threaded")]
let ret = Builder::new().threaded_scheduler().build();
- #[cfg(all(not(feature = "rt-full"), feature = "rt-core"))]
+ #[cfg(all(not(feature = "rt-threaded"), feature = "rt-core"))]
let ret = Builder::new().basic_scheduler().build();
#[cfg(not(feature = "rt-core"))]
@@ -304,7 +305,7 @@ impl Runtime {
{
match &self.kind {
Kind::Shell(_) => panic!("task execution disabled"),
- #[cfg(feature = "rt-full")]
+ #[cfg(feature = "rt-threaded")]
Kind::ThreadPool(exec) => exec.spawn(future),
Kind::Basic(exec) => exec.spawn(future),
}
@@ -330,7 +331,7 @@ impl Runtime {
Kind::Shell(exec) => exec.block_on(future),
#[cfg(feature = "rt-core")]
Kind::Basic(exec) => exec.block_on(future),
- #[cfg(feature = "rt-full")]
+ #[cfg(feature = "rt-threaded")]
Kind::ThreadPool(exec) => exec.block_on(future),
})
}