smol/src/lib.rs

63 lines
1.9 KiB
Rust
Raw Permalink Normal View History

2020-07-20 18:40:27 +00:00
//! A small and fast async runtime.
2020-04-12 16:31:51 +00:00
//!
2020-08-30 20:32:10 +00:00
//! 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.
//!
2020-07-20 18:40:27 +00:00
//! # Examples
2020-04-16 14:09:22 +00:00
//!
2020-07-23 10:24:16 +00:00
//! Connect to an HTTP website, make a GET request, and pipe the response to the standard output:
2020-04-12 16:31:51 +00:00
//!
2020-07-23 10:24:16 +00:00
//! ```
2020-08-26 21:59:49 +00:00
//! use smol::{io, net, prelude::*, Unblock};
2020-07-23 10:24:16 +00:00
//!
//! fn main() -> io::Result<()> {
2020-08-26 21:59:49 +00:00
//! smol::block_on(async {
//! let mut stream = net::TcpStream::connect("example.com:80").await?;
2020-07-23 10:24:16 +00:00
//! 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());
2020-09-20 16:29:46 +00:00
//! io::copy(stream, &mut stdout).await?;
2020-07-23 10:24:16 +00:00
//! Ok(())
2020-04-12 16:31:51 +00:00
//! })
//! }
//! ```
2020-04-13 20:47:55 +00:00
//!
2020-08-30 20:32:10 +00:00
//! There's a lot more in the [examples] directory.
2020-07-14 19:19:01 +00:00
//!
2020-08-30 20:32:10 +00:00
//! [`async-compat`]: https://docs.rs/async-compat
2020-12-23 20:31:12 +00:00
//! [examples]: https://github.com/smol-rs/smol/tree/master/examples
//! [get-request]: https://github.com/smol-rs/smol/blob/master/examples/get-request.rs
2020-03-23 13:07:07 +00:00
#![doc(
html_favicon_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
)]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
)]
2020-07-14 19:19:01 +00:00
#![forbid(unsafe_code)]
2020-02-28 22:22:10 +00:00
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
2020-02-04 10:37:24 +00:00
#[cfg(doctest)]
doc_comment::doctest!("../README.md");
2020-07-23 10:24:16 +00:00
#[doc(inline)]
2020-07-20 18:40:27 +00:00
pub use {
2020-08-26 21:59:49 +00:00
async_executor::{Executor, LocalExecutor, Task},
async_io::{block_on, Async, Timer},
2020-07-20 18:40:27 +00:00
blocking::{unblock, Unblock},
2020-10-09 12:16:52 +00:00
futures_lite::{future, io, pin, prelude, ready, stream},
2020-07-20 18:40:27 +00:00
};
2020-08-26 21:59:49 +00:00
#[doc(inline)]
2021-09-22 11:02:58 +00:00
pub use {async_channel as channel, async_fs as fs, async_lock as lock, async_net as net};
#[cfg(not(target_os = "espidf"))]
#[doc(inline)]
pub use async_process as process;
2020-08-26 21:59:49 +00:00
2020-10-09 12:16:52 +00:00
mod spawn;
pub use spawn::spawn;