Expand description
Traits for async local IO, and implementations for local files, http resources and memory. This crate provides two core traits: AsyncSliceReader and AsyncSliceWriter.
Memory implementations for Bytes and BytesMut are provided by default, file and http are behind features.
Futures for the two core traits are not required to be Send.
This allows implementing these traits for types that are not thread safe, such as many embedded databases.
It also allows for omitting thread synchronization primitives. E.g. you could use an
Rc<RefCell<BytesMut>>
instead of a much more costly Arc<Mutex<BytesMut>>
.
The downside is that you have to use a local executor, e.g. LocalPoolHandle, if you want to do async IO in a background task.
A good blog post providing a rationale for these decisions is Local Async Executors and Why They Should be the Default.
All futures returned by this trait must be polled to completion, otherwise all subsequent calls will produce an io error.
So it is fine to e.g. limit a call to read_at with a timeout, but once a future is dropped without being polled to completion, the reader is not useable anymore.
All methods, even those that do not modify the underlying resource, take a mutable reference to self. This is to enforce linear access to the underlying resource.
In general it is assumed that readers are cheap, so in case of an error you can always get a new reader. Also, if you need concurrent access to the same resource, create multiple readers.
One thing you might wonder is why there are separate methods for writing Bytes and writing slices. The reason is that if you already have Bytes and the underlying writer needs Bytes, you can avoid an allocation.
Modules§
- file
- Support for the File
- http_
adapter - Support for the HttpAdapter
- stats
- Utilities for measuring time for io ops.
Structs§
- Concatenate
Slice Writer - Utility to convert an AsyncWrite into an AsyncSliceWriter by just ignoring the offsets
- File
- A wrapper around a std::fs::File that implements AsyncSliceReader and AsyncSliceWriter
- Http
Adapter - A struct that implements AsyncSliceReader using HTTP range requests
- Tokio
Stream Reader - Utility to convert a tokio::io::AsyncRead into an AsyncStreamReader.
- Tokio
Stream Writer - Utility to convert a tokio::io::AsyncWrite into an AsyncStreamWriter.
Traits§
- Async
Slice Reader - A trait to abstract async reading from different resource.
- Async
Slice Reader Ext - Extension trait for AsyncSliceReader.
- Async
Slice Writer - A trait to abstract async writing to different resources.
- Async
Stream Reader - A non seekable reader, e.g. a network socket.
- Async
Stream Writer - A non seekable writer, e.g. a network socket.