nb-blocking-util
Procedural macro utility for removing async / await code from a function, assuming the interfaces have both an async and a blocking version of the functions called.
For example, reqwest's reqwest::Client and reqwest::blocking::Client expose a very similar interface, so often it is enough to just remove .awaits.
Example usage
Let's say you have a function that fetches https://rust-lang.org/, by using a reqwest client:
async
And now you want to implement the same function if #[cfg(feature = "blocking")], but blocking, gating the previous behind #[cfg(not(feature = "blocking"))]
Of course you can do that, but this macro may help you get rid of duplicates like that:
// First expose a ReqwestClient to the function.
type ReqwestClient = Client;
type ReqwestClient = Client;
// Then the function
async
And now everything left is put it behind
the #[blocking] attribute if #[cfg(feature = "blocking")]:
async