Why are some trait methods declared as synchronous when they return a Future?

⚓ Rust    📅 2025-12-02    👤 surdeus    👁️ 8      

surdeus

Warning

This post was published 46 days ago. The information described in this article may have changed.

I am writing an implementation of the bb8::ManageConnection trait.

The documentation lists the methods as synchronous (declaring them with fn and not async fn), but they return futures. This is apparently standard Rust, so why is it done like this?

AI tells me that this gives the code more flexibility and allows the caller to be unconcerned with whether the function is async or not. But, if the function returns a future wouldn't the caller have to know this in order to handle it?

If synchronous and asynchronous return types are mutually exclusive (an fn must not return a future, an async fn must return a future) how would this provide any flexibility at all? It seems like it just makes it confusing by not having a mismatched sync status and return type.

3 posts - 2 participants

Read full topic

🏷️ Rust_feed