fut-compat
Offers compatibility between the tokio and async_std runtimes by providing their most important functionalities through an unified interface.
The goal of this crate is to enable the developement of async crates which can make use of all the important objects (e.g. File, TcpListener, etc.) and functions (e.g. spawn for spawning new tasks) provided by fully-fledged async runtimes without relying on a concrete runtime. This enables downstream developers to choose the runtime which fits their needs best.
This is archieved by providing abstractions over all important functionalities and implementing them for the respective runtimes by using their respective objects and methods. We either make us of traits already given by the futures crate maintained by the rust team, or we define our own.
Features
By default no runtime specific implementation is included to reduce the number of crates you have to import. In order to use a specific runtime you must activate the corresponding feature:
| Feature | Runtime |
|---|---|
tokio-rt |
tokio |
async-std-rt |
async_std |
Example
The futures crate defines the Spawn trait which abstracts away the spawn methods provided by the tokio and async_std runtimes which are used to spawn new tasks.
This crate provides two objects TokioExecutor and AsyncStdExecutor which implement the Spawn trait by internally calling the spawn method of the respective runtime. Now you can write code which internally requires a way of spawning new tasks without relying on a particular runtime.
use ;
// Replace with AsyncStdExecutor for making use of the async_std runtime instead.
use TokioExecutor;
// Replace with [async_std::main] if needed so.
async
TODO
- Task management
- Make it possible to spawn new tasks.
- Make it possible to spawn new blocking tasks.
- Make it possible to abort tasks.
- Provide gracefull handling of panicked tasks. (asnyc-std does not seem to support this, unlike tokio)
- IO
- Provide compatibility between tokio objects and the futures io traits (
AsyncReadetc.). - Provide compatibility between sync io traits and async io traits. (Re-exported
AllowStdIofromfutures::io) - Provide buffered reading/writing. (Re-exported
BufReaderandBufWriterfromfutures::io) - Provide common helper functions. (Re-exported them from
futures::io) - Add a
copy_bidirectionalhelper function. - Provide async access to
Stdout/Stdin/Stderr.
- Provide compatibility between tokio objects and the futures io traits (
- Filesystem
- Provide access to all common utility functions (e.g.
create_dir,read_to_stringetc.). - Provide a common interface to reading directories.
- Provide a common
Fileinterface. - Provide a common interface for opening
Files with custom options.
- Provide access to all common utility functions (e.g.
- Networking
- Provide common
TcpListener/TcpSocketinterfaces. - Provide common
UnixListener/UnixSocketinterfaces. - Provide a common
UdpSocketinterface.
- Provide common
- Process management
- Make it possible to spawn new processes.
- Make it possible to abort spawned processes.
- Provide a common
Commandinterface. - Provide async access to
Stdout/Stdin/Stderrof started processes. - Reading/sending signals.
- Documentation
- Provide basic documentation.
- Provide a more detailed documentation.
- Add examples everywhere.
License
This library is licensed under the MIT license.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this library by you, shall be licensed as MIT, without any additional terms or conditions.