Docs.rs
  • async-std-1.6.0
    • async-std 1.6.0
    • Docs.rs crate page
    • Apache-2.0/MIT
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • skade
    • yoshuawuyts
    • Keruspe
    • joshtriplett
    • dignifiedquire
    • Dependencies
      • async-attributes ^1.1.1 normal
      • async-task ^3.0.0 normal
      • crossbeam-utils ^0.7.2 normal
      • futures-core ^0.3.4 normal
      • futures-io ^0.3.4 normal
      • kv-log-macro ^1.0.4 normal
      • log ^0.4.8 normal
      • memchr ^2.3.3 normal
      • num_cpus ^1.12.0 normal
      • once_cell ^1.3.1 normal
      • pin-project-lite ^0.1.4 normal
      • pin-utils ^0.1.0-alpha.4 normal
      • slab ^0.4.2 normal
      • surf ^1.0.3 normal
      • femme ^1.3.0 dev
      • futures ^0.3.4 dev
      • rand ^0.7.3 dev
      • rand_xorshift ^0.2.0 dev
      • tempdir ^0.3.7 dev
      • smol ^0.1.10 normal
      • futures-channel ^0.3.4 normal
      • futures-timer ^3.0.2 normal
      • wasm-bindgen-futures ^0.4.10 normal
      • wasm-bindgen-test ^0.3.10 dev
    • Versions
  • Go to latest version
  • Platform
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation
☰
logo

Crate async_std

See all async_std's items

  • Modules
  • Macros

Crates

  • async_std
Change settings

[−][src]Crate async_std

[−] Expand description

Async version of the Rust standard library

async-std is a foundation of portable Rust software, a set of minimal and battle-tested shared abstractions for the broader Rust ecosystem. It offers std types, like Future and Stream, library-defined operations on language primitives, standard macros, I/O and multithreading, among many other things.

async-std is available from crates.io. Once included, async-std can be accessed in use statements through the path async_std, as in use async_std::future.

How to read this documentation

If you already know the name of what you are looking for, the fastest way to find it is to use the search bar at the top of the page.

Otherwise, you may want to jump to one of these useful sections:

  • async_std::* modules
  • Async macros
  • The Async Prelude
  • Cargo.toml feature flags
  • Examples

If this is your first time, the documentation for async-std is written to be casually perused. Clicking on interesting things should generally lead you to interesting places. Still, there are important bits you don't want to miss, so read on for a tour of the async-std and its documentation!

Once you are familiar with the contents of async-std you may begin to find the verbosity of the prose distracting. At this stage in your development you may want to press the [-] button near the top of the page to collapse it into a more skimmable view.

While you are looking at that [-] button also notice the [src] button. Rust's API documentation comes with the source code and you are encouraged to read it. The async-std source is generally high quality and a peek behind the curtains is often enlightening.

Modules in this crate are organized in the same way as in std, except blocking functions have been replaced with async functions and threads have been replaced with lightweight tasks.

You can find more information, reading materials, and other resources here:

  • The async-std website
  • The async-std book
  • GitHub repository
  • List of code examples
  • Discord chat

What is in the async-std documentation?

First, async-std is divided into a number of focused modules, all listed further down this page. These modules are the bedrock upon which async Rust is forged, and they have mighty names like async_std::os and async_std::task. Modules' documentation typically includes an overview of the module along with examples, and are a smart place to start familiarizing yourself with the library.

Second, async-std defines The Async Prelude, a small collection of items - mostly traits - that should be imported into every module of every async crate. The traits in the prelude are pervasive, making the prelude documentation a good entry point to learning about the library.

And finally, async-std exports a number of async macros, and lists them on this page.

Contributing changes to the documentation

Check out async-std's contribution guidelines here. The source for this documentation can be found on GitHub. To contribute changes, make sure you read the guidelines first, then submit pull requests for your suggested changes.

Contributions are appreciated! If you see a part of the docs that can be improved, submit a PR, or chat with us first on Discord.

A tour of async-std

The rest of this crate documentation is dedicated to pointing out notable features of async-std.

Platform abstractions and I/O

Besides basic data types, async-std is largely concerned with abstracting over differences in common platforms, most notably Windows and Unix derivatives.

Common types of I/O, including files, TCP, UDP, are defined in the io, fs, and net modules.

The task module contains async-std's task abstractions. sync contains further primitive shared memory types, including channel, which contains the channel types for message passing.

Timeouts, intervals, and delays

async-std provides several methods to manipulate time:

  • task::sleep to wait for a duration to pass without blocking.
  • stream::interval for emitting an event at a set interval.
  • future::timeout to time-out futures if they don't resolve within a set interval.

Examples

All examples require the "attributes" feature to be enabled. This feature is not enabled by default because it significantly impacts compile times. See task::block_on for an alternative way to start executing tasks.

Call an async function from the main function:

async fn say_hello() {
    println!("Hello, world!");
}

#[async_std::main]
async fn main() {
    say_hello().await;
}

Await two futures concurrently, and return a tuple of their output:

use async_std::prelude::*;

#[async_std::main]
async fn main() {
    let a = async { 1u8 };
    let b = async { 2u8 };
    assert_eq!(a.join(b).await, (1u8, 2u8))
}

Create a UDP server that echoes back each received message to the sender:

use async_std::net::UdpSocket;

#[async_std::main]
async fn main() -> std::io::Result<()> {
    let socket = UdpSocket::bind("127.0.0.1:8080").await?;
    println!("Listening on {}", socket.local_addr()?);

    let mut buf = vec![0u8; 1024];

    loop {
        let (recv, peer) = socket.recv_from(&mut buf).await?;
        let sent = socket.send_to(&buf[..recv], &peer).await?;
        println!("Sent {} out of {} bytes to {}", sent, recv, peer);
    }
}

Features

Items marked with unstable are available only when the unstable Cargo feature is enabled:

[dependencies.async-std]
version = "1.6.0"
features = ["unstable"]

Items marked with attributes are available only when the attributes Cargo feature is enabled:

[dependencies.async-std]
version = "1.6.0"
features = ["attributes"]

Additionally it's possible to only use the core traits and combinators by only enabling the std Cargo feature:

[dependencies.async-std]
version = "1.6.0"
default-features = false
features = ["std"]

And to use async-std on no_std targets that only support alloc only enable the alloc Cargo feature:

[dependencies.async-std]
version = "1.6.0"
default-features = false
features = ["alloc"]

Runtime configuration

Several environment variables are available to tune the async-std runtime:

  • ASYNC_STD_THREAD_COUNT: The number of threads that the async-std runtime will start. By default, this is one per logical cpu as reported by the num_cpus crate, which may be different than the number of physical cpus. Async-std will panic if this is set to any value other than a positive integer.
  • ASYNC_STD_THREAD_NAME: The name that async-std's runtime threads report to the operating system. The default value is "async-std/runtime".

Modules

fs

Filesystem manipulation operations.

future

Asynchronous values.

io

Traits, helpers, and type definitions for core I/O functionality.

net

Networking primitives for TCP/UDP communication.

os

OS-specific extensions.

path

Cross-platform path manipulation.

pinunstable

Types that pin data to its location in memory.

prelude

The async prelude.

processunstable

A module for working with processes.

stream

Composable asynchronous iteration.

sync

Synchronization primitives.

task

Types and traits for working with asynchronous tasks.

Macros

eprintunstable

Prints to the standard error.

eprintlnunstable

Prints to the standard error, with a newline.

printunstable

Prints to the standard output.

printlnunstable

Prints to the standard output, with a newline.

task_local

Declares task-local values.

write

Writes formatted data into a buffer.

writeln

Write formatted data into a buffer, with a newline appended.

Attribute Macros

mainattributes

Enables an async main function.

testattributes

Enables an async test function.

Results for eq

In Names
(151)
In Parameters
(0)
In Return Types
(0)
async_std::stream::Stream::eqDetermines if the elements of this `Stream` are… 
async_std::stream::StreamExt::eqDetermines if the elements of this `Stream` are… 
async_std::sync::Arc::eqEquality for two `Arc`s. 
async_std::fs::FileType::eq 
async_std::fs::Permissions::eq 
async_std::future::TimeoutError::eq 
async_std::io::ErrorKind::eq 
async_std::io::SeekFrom::eq 
async_std::net::IpAddr::eq 
async_std::net::SocketAddr::eq 
async_std::net::Ipv4Addr::eq 
async_std::net::SocketAddrV4::eq 
async_std::net::Shutdown::eq 
async_std::net::AddrParseError::eq 
async_std::net::Ipv6Addr::eq 
async_std::net::SocketAddrV6::eq 
async_std::path::Prefix::eq 
async_std::path::PrefixComponent::eq 
async_std::path::StripPrefixError::eq 
async_std::path::Component::eq 
async_std::path::Components::eq 
async_std::path::Path::eq 
async_std::path::PathBuf::eq 
async_std::pin::Pin::eq 
async_std::process::ExitStatus::eq 
async_std::process::Output::eq 
async_std::stream::TimeoutError::eq 
async_std::sync::TrySendError::eq 
async_std::sync::TryRecvError::eq 
async_std::sync::RecvError::eq 
async_std::task::Poll::eq 
async_std::task::TaskId::eq 
async_std::task::AccessError::eq 
async_std::sync::Arc::ptr_eqReturns `true` if the two `Arc`s point to the same… 
async_std::sync::Weak::ptr_eqReturns `true` if the two `Weak`s point to the same… 
async_std::fsFilesystem manipulation operations. 
async_std::os::unix::fsUnix-specific filesystem extensions. 
async_std::os::windows::fsWindows-specific filesystem extensions. 
async_std::stream::Stream::geDetermines if the elements of this `Stream` are… 
async_std::stream::StreamExt::geDetermines if the elements of this `Stream` are… 
async_std::sync::Arc::ge'Greater than or equal to' comparison for two `Arc`s. 
async_std::net::IpAddr::ge 
async_std::path::Component::ge 
async_std::path::Prefix::ge 
async_std::path::Components::ge 
async_std::path::Path::ge 
async_std::path::PathBuf::ge 
async_std::pin::Pin::ge 
async_std::task::Poll::ge 
async_std::stream::Stream::gtDetermines if the elements of this `Stream` are… 
async_std::stream::StreamExt::gtDetermines if the elements of this `Stream` are… 
async_std::sync::Arc::gtGreater-than comparison for two `Arc`s. 
async_std::net::IpAddr::gt 
async_std::path::Component::gt 
async_std::path::Prefix::gt 
async_std::path::Components::gt 
async_std::path::Path::gt 
async_std::path::PathBuf::gt 
async_std::pin::Pin::gt 
async_std::task::Poll::gt 
async_std::process::idReturns the OS-assigned process identifier associated with… 
async_std::task::Task::idGets the task's unique identifier. 
async_std::ioTraits, helpers, and type definitions for core I/O… 
async_std::os::unix::ioUnix-specific I/O extensions. 
async_std::os::windows::ioWindows-specific I/O extensions. 
async_std::net::SocketAddr::ipReturns the IP address associated with this socket address. 
async_std::net::SocketAddrV4::ipReturns the IP address associated with this socket address. 
async_std::net::SocketAddrV6::ipReturns the IP address associated with this socket address. 
async_std::stream::Stream::leDetermines if the elements of this `Stream` are… 
async_std::stream::StreamExt::leDetermines if the elements of this `Stream` are… 
async_std::sync::Arc::le'Less than or equal to' comparison for two `Arc`s. 
async_std::net::IpAddr::le 
async_std::path::Component::le 
async_std::path::Prefix::le 
async_std::path::Components::le 
async_std::path::Path::le 
async_std::path::PathBuf::le 
async_std::pin::Pin::le 
async_std::task::Poll::le 
async_std::stream::Stream::ltDetermines if the elements of this `Stream` are… 
async_std::stream::StreamExt::ltDetermines if the elements of this `Stream` are… 
async_std::sync::Arc::ltLess-than comparison for two `Arc`s. 
async_std::net::IpAddr::lt 
async_std::path::Component::lt 
async_std::path::Prefix::lt 
async_std::path::Components::lt 
async_std::path::Path::lt 
async_std::path::PathBuf::lt 
async_std::pin::Pin::lt 
async_std::task::Poll::lt 
async_std::stream::Stream::neDetermines if the elements of this `Stream` are… 
async_std::stream::StreamExt::neDetermines if the elements of this `Stream` are… 
async_std::sync::Arc::neInequality for two `Arc`s. 
async_std::fs::FileType::ne 
async_std::fs::Permissions::ne 
async_std::future::TimeoutError::ne 
async_std::io::SeekFrom::ne 
async_std::net::SocketAddr::ne 
async_std::net::AddrParseError::ne 
async_std::net::IpAddr::ne 
async_std::path::Prefix::ne 
async_std::path::StripPrefixError::ne 
async_std::path::Component::ne 
async_std::path::Components::ne 
async_std::path::Path::ne 
async_std::path::PathBuf::ne 
async_std::pin::Pin::ne 
async_std::process::ExitStatus::ne 
async_std::process::Output::ne 
async_std::stream::TimeoutError::ne 
async_std::sync::TrySendError::ne 
async_std::task::Poll::ne 
async_std::task::TaskId::ne 
async_std::task::AccessError::ne 
async_std::osOS-specific extensions. 
async_std::net::IpAddr::V4An IPv4 address. 
async_std::net::SocketAddr::V4An IPv4 socket address. 
async_std::net::IpAddr::V6An IPv6 address. 
async_std::net::SocketAddr::V6An IPv6 socket address. 
async_std::io::SeekFrom::EndSets the offset to the size of this object plus the… 
async_std::fs::Metadata::lenReturns the file size in bytes. 
async_std::stream::ExactSizeStream::lenReturns the exact number of times the stream will iterate. 
async_std::sync::Sender::lenReturns the number of messages in the channel. 
async_std::sync::Receiver::lenReturns the number of messages in the channel. 
async_std::stream::Pending::len 
async_std::netNetworking primitives for TCP/UDP communication. 
async_std::os::unix::netUnix-specific networking extensions. 
async_std::fs::DirBuilder::newCreates a blank set of options. 
async_std::fs::OpenOptions::newCreates a blank set of options. 
async_std::io::BufReader::newCreates a buffered reader with default buffer capacity. 
async_std::io::BufWriter::newCreates a new `BufWriter` with a default buffer capacity.… 
async_std::io::Cursor::newCreates a new cursor wrapping the provided underlying… 
async_std::io::Error::newCreates a new I/O error from a known kind of error as well… 
async_std::io::IoSlice::newCreates a new `IoSlice` wrapping a byte slice. 
async_std::io::IoSliceMut::newCreates a new `IoSliceMut` wrapping a byte slice. 
async_std::net::Ipv4Addr::newCreates a new IPv4 address from four eight-bit octets. 
async_std::net::Ipv6Addr::newCreates a new IPv6 address from eight 16-bit segments. 
async_std::net::SocketAddr::newCreates a new socket address from an [IP address] and a… 
async_std::net::SocketAddrV4::newCreates a new socket address from an [IPv4 address] and a… 
async_std::net::SocketAddrV6::newCreates a new socket address from an [IPv6 address], a… 
async_std::path::Path::newDirectly wraps a string slice as a `Path` slice. 
async_std::path::PathBuf::newAllocates an empty `PathBuf`. 
async_std::pin::Pin::newConstruct a new `Pin<P>` around a pointer to some data of… 
async_std::sync::Mutex::newCreates a new mutex. 
async_std::sync::RwLock::newCreates a new reader-writer lock. 
async_std::sync::Barrier::newCreates a new barrier that can block a given number of… 
async_std::sync::Condvar::newCreates a new condition variable 
async_std::sync::Arc::newConstructs a new `Arc<T>`. 
async_std::sync::Weak::newConstructs a new `Weak<T>`, without allocating any memory.… 
async_std::task::Builder::newCreates a new builder. 
async_std::pin::Pin::setAssigns a new value to the memory behind the pinned… 
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.

Keyboard Shortcuts

?
Show this help dialog
S
Focus the search field
↑
Move up in search results
↓
Move down in search results
↹
Switch tab
⏎
Go to active search result
+
Expand all sections
-
Collapse all sections

Search Tricks

Prefix searches with a type followed by a colon (e.g., fn:) to restrict the search to a given type.

Accepted types are: fn, mod, struct, enum, trait, type, macro, and const.

Search functions by type signature (e.g., vec -> usize or * -> vec)

Search multiple things at once by splitting your query with comma (e.g., str,u8 or String,struct:Vec,test)

You can look for items with an exact name by putting double quotes around your request: "string"

Look for items inside another one by searching for a path: vec::Vec