Crates.io | dyn-future |
lib.rs | dyn-future |
version | 3.0.4 |
source | src |
created_at | 2019-12-02 15:22:48.91772 |
updated_at | 2019-12-04 15:22:10.004744 |
description | Convenient and fast dynamic Futures for Rust. |
homepage | |
repository | https://github.com/xacrimon/dyn-future |
max_upload_size | |
id | 185936 |
size | 11,661 |
This is a small crate implementing convenient and fast dynamic Futures in Rust.
The DynFuture<T>
type this library provides is intended as a replacement
for the naive Box<dyn Future<Output = T>>
.
This library is designed to be dead simple to use and require no setup. You can freely mix the naive boxed futures from dependencies and such without issue.
DynFuture<T>
can be used the same way as Box<dyn Future<Output = T>>
and most of the time you can just run find and replace on your existing code.
DynFuture<T>
can be awaited like any other future, but it has a fixed size.
It should only be used as a replacement for Box<dyn Future<Output = T>>
.
If it is possible you should always prefer statically resolved futures using async fn
.
dyn-future strives to be small and to minimize dependencies. If you have any questions or improvements to make, feel free to open an issue.
The provided DynFuture<T>
type is faster than the naive implementation.
Exactly how much depends on the global allocator, amount of CPU logical processors
and the sizes of the futures sent. Though in general DynFuture<T>
is always faster.
Currently we provide some extremely simple benchmarks. These could absolutely be improved. This is something I would like help with as I am not fantastic at writing benchmarks.
There are not representative of real world gains due to the lack of variation of future types. I have done some minor benchmarking of a proprietary codebase using dyn-future with over 8x gains in time spent handling dynamic futures.
dyn-future gladly accepts contributions!
Open a PR and I will take a look.