Expand description
A small and fast async runtime.
This crate simply re-exports other smaller async crates (see the source).
To use tokio-based libraries with smol, apply the async-compat
adapter to futures and I/O
types.
See the smol-macros
crate if you want a no proc-macro, fast compiling, easy-to-use
async main and/or multi-threaded Executor setup out of the box.
§Examples
Connect to an HTTP website, make a GET request, and pipe the response to the standard output:
use smol::{io, net, prelude::*, Unblock};
fn main() -> io::Result<()> {
smol::block_on(async {
let mut stream = net::TcpStream::connect("example.com:80").await?;
let req = b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n";
stream.write_all(req).await?;
let mut stdout = Unblock::new(std::io::stdout());
io::copy(stream, &mut stdout).await?;
Ok(())
})
}
There’s a lot more in the examples directory.
Modules§
- channel
- An async multi-producer multi-consumer channel, where each message can be received by only one of all existing consumers.
- fs
- Async filesystem primitives.
- future
- Combinators for the
Future
trait. - io
- Tools and combinators for I/O.
- lock
- Async synchronization primitives.
- net
- Async networking primitives for TCP/UDP/Unix communication.
- prelude
- Traits
Future
,Stream
,AsyncRead
,AsyncWrite
,AsyncBufRead
,AsyncSeek
, and their extensions. - process
- Async interface for working with processes.
- stream
- Combinators for the
Stream
trait.
Macros§
- pin
- Pins a variable of type
T
on the stack and rebinds it asPin<&mut T>
. - ready
- Unwraps
Poll<T>
or returnsPending
.
Structs§
- Async
- Async adapter for I/O types.
- Executor
- An async executor.
- Local
Executor - A thread-local executor.
- Task
- A spawned task.
- Timer
- A future or stream that emits timed events.
- Unblock
- Runs blocking I/O on a thread pool.