#future #futures #promise #dynamic #fast #type #replacement

dyn-future

Convenient and fast dynamic Futures for Rust

14 stable releases

✓ Uses Rust 2018 edition

new 3.0.4 Dec 4, 2019
3.0.1 Dec 3, 2019
2.1.3 Dec 3, 2019
1.0.1 Dec 2, 2019

44 downloads per month

MIT license

9KB
165 lines

dyn-future

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>>.

Usability

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.

Compilation overhead

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.

Why?

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.

Contributing

dyn-future gladly accepts contributions!

Open a PR and I will take a look.

Dependencies

~90KB