refactor(workspace): standardise on async_trait, drop hand-rolled BoxFuture - #698
refactor(workspace): standardise on async_trait, drop hand-rolled BoxFuture#698varex83agent wants to merge 1 commit into
Conversation
emlautarom1
left a comment
There was a problem hiding this comment.
Not sure we gain much from switching between native and async_trait definitions. I'd suggest using async_trait everywhere that we have a trait with an async method for consistency. Be consistent on the attribute usage: either #[async_trait::async_trait] or #[async_trait]. Also remove the comments detailing how the trait is being used, it can and will get stale and provides no value at all to the reader.
The replacement of the custom BoxFuture with the one from futures makes sense and looks good.
| /// | ||
| /// Held as `Arc<dyn Consensus>` by [`ConsensusWrapper`] and the controller, so | ||
| /// the trait must stay dyn-compatible and keeps `#[async_trait]`. |
There was a problem hiding this comment.
Drop these kind of comments.
There was a problem hiding this comment.
Done — removed.
…Future Traits that hand-rolled `BoxFuture`-returning methods purely to wrap already-async inherent methods (`consensus::wrapper::Consensus`, `dkg::bcast::RegisteredMessage`) now declare plain `async fn` under `#[async_trait]`, and `priority`'s non-trait `send_receive` is a plain `async fn`. Every trait with an async method uses `#[async_trait]`, spelled the same way workspace-wide (bare attribute plus `use async_trait::async_trait`, which was already the majority form). `cli`'s `DiskTestTool` joins them, retiring the lone `#[allow(async_fn_in_trait)]`. Drops `core`'s duplicate `BoxFuture` alias in favour of `futures::future::BoxFuture`. Out of scope and untouched: the libp2p `ConnectionHandler` state-machine `BoxFuture`s, and the subscriber callback type aliases owned by #606. Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
bbdb5c3 to
f58fd00
Compare
|
Thanks — reworked to go the other way. Everything with an async trait method is now
One judgement call worth a look: Note this inverts #613's acceptance criterion (" Gates: |
Closes #613.
Reworked after review: instead of splitting traits between native async-fn-in-trait and
#[async_trait], every trait with an async method now uses#[async_trait].BoxFuture-returning methods purely to wrap already-async inherent methods (consensus::wrapper::Consensus,dkg::bcast::RegisteredMessage) now declare plainasync fn.priority's non-traitsend_receiveis a plainasync fninstead of returning a boxed future.#[async_trait]plususe async_trait::async_trait, which was already the majority form (29 vs 6). The six qualified#[async_trait::async_trait]uses were normalised.cli'sDiskTestTool— the one native-AFIT trait in the tree — joins them, retiring the lone#[allow(async_fn_in_trait)]and its comment.core's duplicateBoxFuturealias is dropped in favour offutures::future::BoxFuture.Out of scope and untouched: the libp2p
ConnectionHandlerstate-machineBoxFutures, and the subscriber callback type aliases owned by #606.Note
This inverts issue #613's stated acceptance criterion ("
#[async_trait]remains only on dyn-used traits") in favour of the uniformity asked for in review. Worth editing or closing #613 to match.Co-Authored-By: Bohdan Ohorodnii 35969035+varex83@users.noreply.github.com