1//! A small and fast async runtime.
2//!
3//! This crate simply re-exports other smaller async crates (see the source).
4//!
5//! To use tokio-based libraries with smol, apply the [`async-compat`] adapter to futures and I/O
6//! types.
7//!
8//! See the [`smol-macros`] crate if you want a no proc-macro, fast compiling, easy-to-use
9//! async main and/or multi-threaded Executor setup out of the box.
10//!
11//! # Examples
12//!
13//! Connect to an HTTP website, make a GET request, and pipe the response to the standard output:
14//!
15//! ```
16//! use smol::{io, net, prelude::*, Unblock};
17//!
18//! fn main() -> io::Result<()> {
19//! smol::block_on(async {
20//! let mut stream = net::TcpStream::connect("example.com:80").await?;
21//! let req = b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n";
22//! stream.write_all(req).await?;
23//!
24//! let mut stdout = Unblock::new(std::io::stdout());
25//! io::copy(stream, &mut stdout).await?;
26//! Ok(())
27//! })
28//! }
29//! ```
30//!
31//! There's a lot more in the [examples] directory.
32//!
33//! [`async-compat`]: https://docs.rs/async-compat/latest/async_compat/
34//! [`smol-macros`]: https://docs.rs/smol-macros/latest/smol_macros/
35//! [examples]: https://github.com/smol-rs/smol/tree/master/examples
36
37#![doc(
38 html_favicon_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
39)]
40#![doc(
41 html_logo_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
42)]
43#![forbid(unsafe_code)]
44#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
45
46#[cfg(doctest)]
47doc_comment::doctest!("../README.md");
48
49#[doc(inline)]
50pub use {
51 async_executor::{Executor, LocalExecutor, Task},
52 async_io::{block_on, Async, Timer},
53 blocking::{unblock, Unblock},
54 futures_lite::{future, io, pin, prelude, ready, stream},
55};
56
57#[doc(inline)]
58pub use {async_channel as channel, async_fs as fs, async_lock as lock, async_net as net};
59
60#[cfg(not(target_os = "espidf"))]
61#[doc(inline)]
62pub use async_process as process;
63
64mod spawn;
65pub use spawn::spawn;
66

Provided by KDAB

Privacy Policy