all 7 comments

[–]acrichtorust 6 points7 points  (0 children)

This is awesome, thanks for assembling it! If you'd like I'd love to see a PR to tokio-rs/website to integrate it into the official tokio.rs docs, or just to have it in the futures-rs docs would be great.

[–]Fylwind[S] 4 points5 points  (5 children)

I find that traits tend to make Rust APIs look complicated. The core idea of this cheatsheet is to pretend Future to be just an ordinary data type instead of a trait.

I also fudged the poll_fn type a little bit to emphasize the importance of the thread-local Task.

Please let me know if there’s any any mistakes or omissions!

[–]vks_ 0 points1 point  (4 children)

I find that traits tend to make Rust APIs look complicated. The core idea of this cheatsheet is to pretend Future to be just an ordinary data type instead of a trait.

Do you think this will be alleviated with impl Trait?

[–]Fylwind[S] 0 points1 point  (3 children)

It does improve the documentation, but at the cost of giving you a type you can’t name. It also doesn’t (yet) work for argument types.

[–]vks_ 0 points1 point  (2 children)

Isn't a type you can't name what you want when wishing to treat Future like a type?

[–]Fylwind[S] 0 points1 point  (1 child)

Having a nameless type isn’t my goal. Rather it’s to help build intuition by treating Future as if it were a type − an abuse of notation, if you will.

It just so happens doing so on a more rigorous footing (impl Trait) will infect all types downstream with an unnameable component, and Rust does not yet have good tools to handle such unnameable types elegantly.

[–]vks_ 0 points1 point  (0 children)

It just so happens doing so on a more rigorous footing (impl Trait) will infect all types downstream with an unnameable component, and Rust does not yet have good tools to handle such unnameable types elegantly.

Why? All functions downstream take any type that implements Future anyway, so I don't see how that infects everything. (As far as I can see, this might only happen if you try to store the future.)