TLDR.Chat

Challenges of Supporting Asynchronous and Synchronous Code in Rust

The bane of my existence: Supporting both async and sync code in Rust ๐Ÿ”—

Sit beside me and hear this crazy old man's tale of when I asked Rust for too much

The article discusses the challenges of supporting both asynchronous and synchronous code in Rust, using the example of creating a library to wrap a public API. The author initially faced difficulties in accommodating both async and sync usage, leading to code duplication and complexity. They explored various solutions, including manual copy-pasting, using block_on to make async code synchronous, and even considering separate crates for async and sync usage. Ultimately, they found success with the "maybe_async" crate, which allowed them to support multiple HTTP clients independently of their async/sync nature. However, they encountered a fundamental problem with feature conflicts in Rust, which led to discussions about potential solutions and the limitations of current approaches. The author reflects on the challenges and complexities involved in supporting both async and sync code and considers potential future directions for addressing these issues in Rust.

Related