Rust Async Runtime Conflict Resolution

For quite some time, I used to support more than one rust async runtime in a single crate. After spend several hours troubleshooting which project has enabled two conflicting feature flags in my crate, I came up with few conclusions: 1. If you need support tokio, smol, monoio, compio or glomio as async runtimes, isolate parts which has calls to their APIs into separate crates, at debugging time you won’t have code paths being mistakenly activated 2. Type aliases are useful, but don’t use them to simple give another name to a struct, like File or RwLock, that will cause compilation errors if feature flags aren’t additive, but exclusive. In short, take a wide picture of your solution, if you codebase has parts which are clearly exclusive to one or another runtime, please save time and do not use a feature flag to support both of them, it will not only add code bloat, but verbose, hard to maintain and debug. #rust #programming #async #bestpratices #softwaredesign #featureflags

To view or add a comment, sign in

Explore content categories