2019-08-12 18:29:06 +00:00
|
|
|
//! Async version of the Rust standard library.
|
2019-08-08 12:44:48 +00:00
|
|
|
//!
|
|
|
|
//! This crate is an async version of [`std`].
|
2019-08-15 13:33:45 +00:00
|
|
|
//! Higher-level documentation in the form of the book
|
|
|
|
//! ["Async programming in Rust with async-std"][book]
|
|
|
|
//! is available.
|
2019-08-08 12:44:48 +00:00
|
|
|
//!
|
|
|
|
//! [`std`]: https://doc.rust-lang.org/std/index.html
|
2019-08-16 13:19:10 +00:00
|
|
|
//! [book]: https://book.async.rs
|
2019-08-08 12:44:48 +00:00
|
|
|
//!
|
|
|
|
//! # Examples
|
|
|
|
//!
|
|
|
|
//! Spawn a task and block the current thread on its result:
|
|
|
|
//!
|
|
|
|
//! ```
|
|
|
|
//! # #![feature(async_await)]
|
|
|
|
//! use async_std::task;
|
|
|
|
//!
|
|
|
|
//! fn main() {
|
|
|
|
//! task::block_on(async {
|
|
|
|
//! println!("Hello, world!");
|
|
|
|
//! })
|
|
|
|
//! }
|
|
|
|
//! ```
|
2019-08-16 14:36:44 +00:00
|
|
|
//!
|
|
|
|
//! Use sockets in a familiar way, with low-friction built-in timeouts:
|
|
|
|
//!
|
|
|
|
//! ```no_run
|
|
|
|
//! #![feature(async_await)]
|
|
|
|
//!
|
|
|
|
//! use std::time::Duration;
|
|
|
|
//!
|
|
|
|
//! use async_std::{
|
|
|
|
//! prelude::*,
|
|
|
|
//! task,
|
|
|
|
//! io,
|
|
|
|
//! net::TcpStream,
|
|
|
|
//! };
|
|
|
|
//!
|
|
|
|
//! async fn get() -> io::Result<Vec<u8>> {
|
|
|
|
//! let mut stream = TcpStream::connect("example.com:80").await?;
|
|
|
|
//! stream.write_all(b"GET /index.html HTTP/1.0\r\n\r\n").await?;
|
|
|
|
//!
|
|
|
|
//! let mut buf = vec![];
|
|
|
|
//!
|
|
|
|
//! io::timeout(Duration::from_secs(5), async {
|
2019-08-16 14:54:39 +00:00
|
|
|
//! stream.read_to_end(&mut buf).await?;
|
2019-08-16 14:36:44 +00:00
|
|
|
//! Ok(buf)
|
|
|
|
//! })
|
2019-08-16 14:54:39 +00:00
|
|
|
//! .await
|
2019-08-16 14:36:44 +00:00
|
|
|
//! }
|
|
|
|
//!
|
|
|
|
//! fn main() {
|
|
|
|
//! task::block_on(async {
|
|
|
|
//! let raw_response = get().await.expect("request");
|
|
|
|
//! let response = String::from_utf8(raw_response)
|
|
|
|
//! .expect("utf8 conversion");
|
|
|
|
//! println!("received: {}", response);
|
|
|
|
//! });
|
|
|
|
//! }
|
|
|
|
//! ```
|
2019-08-08 12:44:48 +00:00
|
|
|
|
|
|
|
#![feature(async_await)]
|
2019-08-12 17:50:30 +00:00
|
|
|
#![cfg_attr(feature = "docs", feature(doc_cfg))]
|
2019-08-08 12:44:48 +00:00
|
|
|
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
2019-08-14 02:22:37 +00:00
|
|
|
#![doc(test(attr(deny(rust_2018_idioms, warnings))))]
|
|
|
|
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
|
2019-08-12 10:43:28 +00:00
|
|
|
#![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")]
|
2019-08-08 12:44:48 +00:00
|
|
|
|
|
|
|
pub mod fs;
|
|
|
|
pub mod future;
|
|
|
|
pub mod io;
|
|
|
|
pub mod net;
|
|
|
|
pub mod os;
|
|
|
|
pub mod prelude;
|
|
|
|
pub mod stream;
|
|
|
|
pub mod sync;
|
|
|
|
pub mod task;
|
|
|
|
|
|
|
|
pub(crate) mod utils;
|