| ▲ | conaclos 5 hours ago | ||||||||||||||||||||||||||||
I recently started working with Rust async. The main issue I am currently facing is code duplication: I have to duplicate every function that I want to support both asynchronous and blocking APIs. This could be great to have a `maybe-async`. I took a look at the available crates to work around this (maybe-async, bisync), but they all have issues or hard limitations. | |||||||||||||||||||||||||||||
| ▲ | K0nserv 3 hours ago | parent | next [-] | ||||||||||||||||||||||||||||
There is work happening on keyword generics[0], which would let a function be generic over keywords like `async` and `const`. For now the best option to write code that wants to live in both worlds is sans-io. Thomas Eizinger at Fireguard has written a good article about this[1] pattern. Not only does it nicely solve the sync/async issue, but it also makes testing easier and opens the door to techniques like DST[2] I have my own writing on the topic[3], which highlights that the problem is wider than just async vs sync due to different executors. 0: https://github.com/rust-lang/effects-initiative 1: https://www.firezone.dev/blog/sans-io 2: https://notes.eatonphil.com/2024-08-20-deterministic-simulat... | |||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
| ▲ | albertzeyer 5 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||
The classic function coloring problem. https://journal.stuffwithstuff.com/2015/02/01/what-color-is-... | |||||||||||||||||||||||||||||
| ▲ | small_scombrus 4 hours ago | parent | prev [-] | ||||||||||||||||||||||||||||
It'll depend immensely on what you're actually doing, but if it's simple enough you may be able to make a macro that subs out the types & awaits | |||||||||||||||||||||||||||||