Docs.rs
  • async-std-1.0.0
    • async-std 1.0.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.0 normal
      • async-macros ^1.0.0 normal
      • async-task ^1.0.0 normal
      • broadcaster ^0.2.6 normal
      • crossbeam-channel ^0.3.9 normal
      • crossbeam-deque ^0.7.1 normal
      • crossbeam-utils ^0.6.6 normal
      • futures-core ^0.3.0 normal
      • futures-io ^0.3.0 normal
      • futures-timer ^1.0.2 normal
      • kv-log-macro ^1.0.4 normal
      • log ^0.4.8 normal
      • memchr ^2.2.1 normal
      • mio ^0.6.19 normal
      • mio-uds ^0.6.7 normal
      • num_cpus ^1.10.1 normal
      • once_cell ^1.2.0 normal
      • pin-project-lite ^0.1 normal
      • pin-utils ^0.1.0-alpha.4 normal
      • slab ^0.4.2 normal
      • femme ^1.2.0 dev
      • futures ^0.3.0 dev
      • rand ^0.7.2 dev
      • tempdir ^0.3.7 dev
    • Versions
  • Go to latest version
  • Platform
    • i686-apple-darwin
    • 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 async-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

Spawn a task and block the current thread on its result:

use async_std::task;

fn main() {
    task::block_on(async {
        println!("Hello, world!");
    })
}

Features

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

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

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

[dependencies.async-std]
version = "1.0.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.0.0"
default-features = false
features = ["std"]

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.

writeunstable

Writes formatted data into a buffer.

writelnunstable

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 pin

In Names
(42)
In Parameters
(124)
In Return Types
(20)
async_std::pinTypes that pin data to its location in memory. 
async_std::pin::PinA pinned pointer. 
async_std::sync::Arc::pinConstructs a new `Pin<Arc<T>>`. If `T` does not implement… 
async_std::prelude::StreamExt::minReturns the element that gives the minimum value. If… 
async_std::stream::Stream::minReturns the element that gives the minimum value. If… 
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::os::unix::fs::DirEntryExt::inoReturns the underlying `d_ino` field in the contained… 
async_std::fs::DirEntry::ino 
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::path::PathBuf::popTruncates `self` to [`self.parent`]. 
async_std::stream::ZipA stream that takes items from two other streams… 
async_std::prelude::StreamExt::zip'Zips up' two streams into a single stream of pairs. 
async_std::stream::Stream::zip'Zips up' two streams into a single stream of pairs. 
async_std::net::TcpListener::bindCreates a new `TcpListener` which will be bound to the… 
async_std::net::UdpSocket::bindCreates a UDP socket from the given address. 
async_std::os::unix::net::UnixDatagram::bindCreates a Unix datagram socket bound to the given path. 
async_std::os::unix::net::UnixListener::bindCreates a Unix datagram listener bound to the given path. 
async_std::prelude::StreamExt::findSearches for an element in a stream that satisfies a… 
async_std::stream::Stream::findSearches for an element in a stream that satisfies a… 
async_std::future::Future::joinWaits for two similarly-typed futures to complete. 
async_std::path::Path::joinCreates an owned [`PathBuf`] with `path` adjoined to `self`. 
async_std::prelude::FutureExt::joinWaits for two similarly-typed futures to complete. 
async_std::io::Error::kindReturns the corresponding `ErrorKind` for this error. 
async_std::path::PrefixComponent::kindReturns the parsed prefix data. 
async_std::mainEnables an async main function. 
async_std::fs::File::openOpens a file in read-only mode. 
async_std::fs::OpenOptions::openOpens a file with the configured options. 
async_std::os::unix::net::UnixDatagram::pairCreates an unnamed pair of connected sockets. 
async_std::os::unix::net::UnixStream::pairCreates an unnamed pair of connected sockets. 
async_std::io::SinkA writer that consumes and drops all data. 
async_std::io::sinkCreates a writer that consumes and drops all data. 
async_std::printPrints to the standard output. 
async_std::pin::Pin::eq 
async_std::pin::Pin::ge 
async_std::pin::Pin::gt 
async_std::pin::Pin::le 
async_std::pin::Pin::lt 
async_std::pin::Pin::ne 
async_std::pin::Pin::cmp 
async_std::future::Future::pollAttempt to resolve the future to a final value,… 
async_std::pin::Pin::poll 
async_std::task::JoinHandle::poll 
async_std::pin::Pin::resume 
async_std::io::BufRead::consumeTells this buffer that `amt` bytes have been consumed from… 
async_std::io::BufReader::consume 
async_std::io::Cursor::consume 
async_std::io::Empty::consume 
async_std::pin::Pin::consume 
async_std::pin::Pin::try_poll 
async_std::task::JoinHandle::try_poll 
async_std::stream::Stream::poll_nextAttempts to receive the next item from the stream. 
async_std::fs::ReadDir::poll_next 
async_std::io::Lines::poll_next 
async_std::net::Incoming::poll_next 
async_std::os::unix::net::Incoming::poll_next 
async_std::pin::Pin::poll_next 
async_std::stream::Chain::poll_next 
async_std::stream::Cloned::poll_next 
async_std::stream::Copied::poll_next 
async_std::stream::Filter::poll_next 
async_std::stream::Fuse::poll_next 
async_std::stream::Inspect::poll_next 
async_std::stream::Map::poll_next 
async_std::stream::Scan::poll_next 
async_std::stream::Skip::poll_next 
async_std::stream::SkipWhile::poll_next 
async_std::stream::StepBy::poll_next 
async_std::stream::Take::poll_next 
async_std::stream::TakeWhile::poll_next 
async_std::stream::Zip::poll_next 
async_std::stream::Merge::poll_next 
async_std::stream::Flatten::poll_next 
async_std::stream::FlatMap::poll_next 
async_std::stream::Timeout::poll_next 
async_std::stream::Empty::poll_next 
async_std::stream::FromFn::poll_next 
async_std::stream::FromIter::poll_next 
async_std::stream::Once::poll_next 
async_std::stream::Repeat::poll_next 
async_std::stream::RepeatWith::poll_next 
async_std::stream::Interval::poll_next 
async_std::sync::Receiver::poll_next 
async_std::io::Read::poll_readAttempt to read from the `AsyncRead` into `buf`. 
async_std::fs::File::poll_read 
async_std::io::BufReader::poll_read 
async_std::io::Cursor::poll_read 
async_std::io::Empty::poll_read 
async_std::io::Repeat::poll_read 
async_std::io::Stdin::poll_read 
async_std::io::StdinLock::poll_read 
async_std::net::TcpStream::poll_read 
async_std::os::unix::net::UnixStream::poll_read 
async_std::pin::Pin::poll_read 
async_std::io::Seek::poll_seekAttempt to seek to an offset, in bytes, in a stream. 
async_std::io::BufReader::poll_seekSeeks to an offset, in bytes, in the underlying reader. 
async_std::io::BufWriter::poll_seekSeek to the offset, in bytes, in the underlying writer. 
async_std::fs::File::poll_seek 
async_std::io::Cursor::poll_seek 
async_std::pin::Pin::poll_seek 
async_std::pin::Pin::into_innerUnwraps this `Pin<P>` returning the underlying pointer. 
async_std::io::Write::poll_closeAttempt to close the object. 
async_std::fs::File::poll_close 
async_std::io::BufWriter::poll_close 
async_std::io::Cursor::poll_close 
async_std::io::Sink::poll_close 
async_std::io::Stderr::poll_close 
async_std::io::StderrLock::poll_close 
async_std::io::Stdout::poll_close 
async_std::io::StdoutLock::poll_close 
async_std::net::TcpStream::poll_close 
async_std::os::unix::net::UnixStream::poll_close 
async_std::pin::Pin::poll_close 
async_std::io::Write::poll_flushAttempt to flush the object, ensuring that any buffered… 
async_std::fs::File::poll_flush 
async_std::io::BufWriter::poll_flush 
async_std::io::Cursor::poll_flush 
async_std::io::Sink::poll_flush 
async_std::io::Stderr::poll_flush 
async_std::io::StderrLock::poll_flush 
async_std::io::Stdout::poll_flush 
async_std::io::StdoutLock::poll_flush 
async_std::net::TcpStream::poll_flush 
async_std::os::unix::net::UnixStream::poll_flush 
async_std::pin::Pin::poll_flush 
async_std::pin::Pin::poll_ready 
async_std::io::Write::poll_writeAttempt to write bytes from `buf` into the object. 
async_std::fs::File::poll_write 
async_std::io::BufWriter::poll_write 
async_std::io::Cursor::poll_write 
async_std::io::Sink::poll_write 
async_std::io::Stderr::poll_write 
async_std::io::StderrLock::poll_write 
async_std::io::Stdout::poll_write 
async_std::io::StdoutLock::poll_write 
async_std::net::TcpStream::poll_write 
async_std::os::unix::net::UnixStream::poll_write 
async_std::pin::Pin::poll_write 
async_std::pin::Pin::start_send 
async_std::pin::Pin::partial_cmp 
async_std::io::BufRead::poll_fill_bufReturns the contents of the internal buffer, filling it… 
async_std::io::BufReader::poll_fill_buf 
async_std::io::Cursor::poll_fill_buf 
async_std::io::Empty::poll_fill_buf 
async_std::pin::Pin::poll_fill_buf 
async_std::pin::Pin::try_poll_next 
async_std::stream::DoubleEndedStream::poll_next_backRemoves and returns an element from the end of the stream. 
async_std::io::Read::poll_read_vectoredAttempt to read from the `AsyncRead` into `bufs` using… 
async_std::io::BufReader::poll_read_vectored 
async_std::io::Cursor::poll_read_vectored 
async_std::net::TcpStream::poll_read_vectored 
async_std::pin::Pin::poll_read_vectored 
async_std::io::Write::poll_write_vectoredAttempt to write bytes from `bufs` into the object using… 
async_std::io::Cursor::poll_write_vectored 
async_std::net::TcpStream::poll_write_vectored 
async_std::pin::Pin::poll_write_vectored 
async_std::pin::Pin::into_inner_uncheckedUnwraps this `Pin<P>` returning the underlying pointer. 
async_std::sync::Arc::pinConstructs a new `Pin<Arc<T>>`. If `T` does not implement… 
async_std::pin::Pin::newConstruct a new `Pin<P>` around a pointer to some data of… 
async_std::pin::Pin::clone 
async_std::pin::Pin::as_mutGets a pinned mutable reference from this pinned pointer. 
async_std::pin::Pin::as_refGets a pinned shared reference from this pinned pointer. 
async_std::pin::Pin::into_refConverts this `Pin<&mut T>` into a `Pin<&T>` with the same… 
async_std::pin::Pin::map_uncheckedConstructs a new pin by mapping the interior value. 
async_std::pin::Pin::new_uncheckedConstruct a new `Pin<P>` around a reference to some data… 
async_std::pin::Pin::map_unchecked_mutConstruct a new pin by mapping the interior value. 
async_std::stream::Sum::sumMethod which takes a stream and generates `Self` from the… 
async_std::prelude::StreamExt::sumSums the elements of a stream. 
async_std::pin::Pin::fromConverts a `Box<T>` into a `Pin<Box<T>>` 
async_std::stream::Extend::extendExtends a collection with the contents of a stream. 
async_std::path::PathBuf::extend 
async_std::prelude::StreamExt::collectTransforms a stream into a collection. 
async_std::stream::Product::productMethod which takes a stream and generates `Self` from the… 
async_std::prelude::StreamExt::productMultiplies all elements of the stream. 
async_std::stream::FromStream::from_streamCreates a value from a stream. 
async_std::path::PathBuf::from_stream 
async_std::sync::Arc::from_stream