Skip to main content
Tokio uses feature flags to reduce compiled code size and dependencies. By default, Tokio enables no features, allowing you to opt into only what you need.

Quick Start

For application development, use the full feature to enable everything:
Cargo.toml
tokio = { version = "1.50", features = ["full"] }
For library development, only enable the features you need:
Cargo.toml
tokio = { version = "1.50", features = ["rt", "net", "io-util"] }
The full feature does not include test-util or unstable features like io-uring and taskdump.

Core Features

Enables tokio::spawn, the current-thread scheduler, and non-scheduler utilities.
tokio = { version = "1.50", features = ["rt"] }
This is the minimal feature needed to run async tasks. Use this for the single-threaded current-thread scheduler.
Enables the multi-threaded, work-stealing scheduler.
tokio = { version = "1.50", features = ["rt-multi-thread"] }
This feature requires the rt feature. It adds the heavier multi-threaded scheduler.
Use this for production applications that need to utilize multiple CPU cores.
Enables #[tokio::main] and #[tokio::test] macros.
tokio = { version = "1.50", features = ["macros"] }
#[tokio::main]
async fn main() {
    println!("Hello world");
}
This feature depends on the tokio-macros crate.

I/O Features

FeatureDescriptionKey Types
netTCP, UDP, and Unix Domain SocketsTcpStream, UdpSocket, UnixStream
io-utilUtility traits and combinators for async I/OAsyncReadExt, AsyncWriteExt
io-stdAsync stdin, stdout, and stderrStdin, Stdout, Stderr
fsAsync filesystem operationsFile, read, write, read_dir

Network Example

Cargo.toml
tokio = { version = "1.50", features = ["rt", "net", "io-util"] }
use tokio::net::TcpListener;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let listener = TcpListener::bind("127.0.0.1:8080").await?;
    
    loop {
        let (mut socket, _) = listener.accept().await?;
        
        tokio::spawn(async move {
            let mut buf = [0; 1024];
            socket.read(&mut buf).await.unwrap();
            socket.write_all(&buf).await.unwrap();
        });
    }
}
The AsyncRead and AsyncWrite traits are always available and don’t require any feature flags.

Synchronization and Time

FeatureDescriptionKey Types
syncAsync synchronization primitivesMutex, RwLock, mpsc, oneshot, watch, broadcast, Barrier, Semaphore
timeTime-related utilitiessleep, interval, timeout, Instant, Duration

Synchronization Example

Cargo.toml
tokio = { version = "1.50", features = ["rt", "sync"] }
use tokio::sync::{mpsc, Mutex};
use std::sync::Arc;

#[tokio::main]
async fn main() {
    let (tx, mut rx) = mpsc::channel(32);
    let shared = Arc::new(Mutex::new(0));
    
    // Send values
    tx.send(1).await.unwrap();
    
    // Receive values
    if let Some(val) = rx.recv().await {
        let mut lock = shared.lock().await;
        *lock += val;
    }
}

Time Example

Cargo.toml
tokio = { version = "1.50", features = ["rt", "time"] }
use tokio::time::{sleep, Duration, timeout};

#[tokio::main]
async fn main() {
    // Sleep for 1 second
    sleep(Duration::from_secs(1)).await;
    
    // Timeout after 5 seconds
    let result = timeout(Duration::from_secs(5), async {
        // Some operation
    }).await;
}

System Features

FeatureDescriptionPlatforms
processSpawn and manage child processesUnix, Windows
signalAsync signal handlingUnix, Windows

Process Example

Cargo.toml
tokio = { version = "1.50", features = ["rt", "process"] }
use tokio::process::Command;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let output = Command::new("echo")
        .arg("Hello, world!")
        .output()
        .await?;
    
    println!("Output: {}", String::from_utf8_lossy(&output.stdout));
    Ok(())
}

Special Features

test-util

Enables testing utilities for the Tokio runtime.
Cargo.toml
[dev-dependencies]
tokio = { version = "1.50", features = ["test-util", "rt", "sync", "time"] }
use tokio::time::{sleep, Duration};

#[tokio::test]
async fn test_with_time() {
    sleep(Duration::from_millis(100)).await;
    assert!(true);
}
The test-util feature enables rt, sync, and time automatically. It provides tokio::test macro and time manipulation utilities.

parking_lot

Optimizes internal synchronization primitives using the parking_lot crate.
Cargo.toml
tokio = { version = "1.50", features = ["full", "parking_lot"] }
This is a performance optimization. It also allows constructing some primitives in const context. MSRV may increase based on parking_lot releases.

Unstable Features

Some features require the --cfg tokio_unstable flag and may have breaking API changes.
Unstable features may break in 1.x releases. Use with caution in production.

Enabling Unstable Features

Add to .cargo/config.toml:
.cargo/config.toml
[build]
rustflags = ["--cfg", "tokio_unstable"]
Or use an environment variable:
export RUSTFLAGS="--cfg tokio_unstable"
cargo build

Available Unstable Features

FeatureDescriptionPlatform
tracingEnables tracing events for debuggingAll
io-uringLinux io_uring support for high-performance I/OLinux only
taskdumpTask dump debugging capabilitiesLinux (aarch64, x86, x86_64)

io-uring Example

Cargo.toml
tokio = { version = "1.50", features = ["io-uring"] }
.cargo/config.toml
[build]
rustflags = ["--cfg", "tokio_unstable"]
io-uring is only available on Linux with --cfg tokio_unstable. It requires kernel support for io_uring.

Complete Feature Table

FeatureDefaultIncluded in fullUnstableDependencies
rt-
rt-multi-threadrt
netmio, socket2
io-utilbytes
io-std-
fs-
sync-
time-
macrostokio-macros
processbytes, signal-hook-registry
signalsignal-hook-registry
parking_lotparking_lot
test-utilrt, sync, time
tracingtracing
io-uringio-uring, libc, slab
taskdumpbacktrace

Choosing Features

For Applications

Use full for convenience during development:
tokio = { version = "1.50", features = ["full"] }

For Libraries

Enable only what you need to minimize dependencies:
# For a library that spawns tasks and uses TCP
tokio = { version = "1.50", features = ["rt", "net"] }

# For a library that needs multi-threading
tokio = { version = "1.50", features = ["rt-multi-thread", "net"] }
Library authors should be conservative with feature flags to avoid forcing unnecessary dependencies on users.

Common Feature Combinations

Basic Async Application

tokio = { version = "1.50", features = ["rt", "macros"] }

Web Server

tokio = { version = "1.50", features = ["rt-multi-thread", "net", "io-util", "macros"] }

CLI Tool with File I/O

tokio = { version = "1.50", features = ["rt", "fs", "io-util", "macros"] }

Background Worker

tokio = { version = "1.50", features = ["rt-multi-thread", "sync", "time", "macros"] }

Build docs developers (and LLMs) love