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§
- Support for the File
- Support for the HttpAdapter
- Utilities for measuring time for io ops.
Structs§
- Utility to convert an AsyncWrite into an AsyncSliceWriter by just ignoring the offsets
- A struct that implements AsyncSliceReader using HTTP range requests
- Utility to convert a tokio::io::AsyncRead into an AsyncStreamReader.
- Utility to convert a tokio::io::AsyncWrite into an AsyncStreamWriter.
Traits§
- A trait to abstract async reading from different resource.
- Extension trait for AsyncSliceReader.
- A trait to abstract async writing to different resources.
- A non seekable reader, e.g. a network socket.
- A non seekable writer, e.g. a network socket.