explaingit

tokio-rs/mio

6,964RustAudience · developerComplexity · 4/5Setup · moderate

TLDR

Mio is a low-level Rust library for non-blocking I/O that wraps each operating system's native event system (epoll, kqueue, IOCP) behind a single consistent API, used as the foundation for async runtimes like Tokio.

Mindmap

mindmap
  root((repo))
    What it does
      Non-blocking IO
      Event notifications
      Cross-platform API
    Supported Platforms
      Linux epoll
      macOS kqueue
      Windows IOCP
    Core Concepts
      Poll object
      Token per socket
      Event loop
    Use Cases
      Async runtimes
      High conn servers
      Network libraries
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a high-performance TCP server in Rust that handles many simultaneous connections without blocking.

USE CASE 2

Write a custom async networking library on top of Mio's event loop, allocating nothing at runtime after setup.

USE CASE 3

Port async networking code across Linux, macOS, Windows, Android, and iOS using Mio's unified cross-platform API.

Tech stack

Rust

Getting it running

Difficulty · moderate Time to first run · 1h+

Requires solid Rust knowledge, beginners should use Tokio instead as Mio is a low-level building block not intended for direct use.

License not specified in the explanation.

In plain English

Mio is a low-level Rust library for handling network connections without blocking. In most programs, when you read from a network socket, the program pauses and waits until data arrives. Non-blocking I/O means the program does not wait: instead, it asks the operating system to notify it when a socket is ready to read or write, and can do other work in between. Mio provides a thin, efficient layer over those operating system notifications. The library wraps the native event systems built into each major operating system. On Linux that is epoll, on macOS and BSD systems it is kqueue, and on Windows it is IOCP. Mio presents a consistent API across all of them, so code written with Mio works on Linux, macOS, Windows, Android, iOS, and several BSD variants without changes. The core concept is a Poll object, which you create once, then register sockets with it. Each socket gets a token, which is just a number you choose. You call poll repeatedly in a loop, and each time it returns a list of events. Each event includes the token of the socket that triggered it, and whether the socket is ready to read, write, or both. You then handle those events in whatever way your program needs. Mio explicitly does not include file operations, thread pools, or timers. Those are intentionally left out to keep the library focused and to avoid overhead that not every program needs. Higher-level libraries, such as Tokio, are built on top of Mio and add those features. The README notes that if you are new to async Rust networking, Tokio is likely a better starting point than using Mio directly. Mio is designed to allocate nothing at runtime after initial setup, which matters for programs handling large numbers of simultaneous connections where memory allocation overhead can become significant. It is used as a building block by several important Rust async runtimes and networking libraries.

Copy-paste prompts

Prompt 1
Show me how to write a basic TCP echo server in Rust using Mio that handles multiple simultaneous connections without blocking.
Prompt 2
I am building a custom async runtime in Rust and want to use Mio as the event loop. Walk me through setting up Poll, registering sockets with tokens, and processing events in a loop.
Prompt 3
How do I use Mio to watch both a TCP socket and a UDP socket at the same time and dispatch events from either in a single loop?
Prompt 4
I am new to Mio and want to understand how it compares to Tokio. Show me how the same simple server looks in both and explain when to choose Mio directly.
Open on GitHub → Explain another repo

← tokio-rs on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.