replace #[async_trait]
with native async trait for trait Resolver
#6751
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refer to: #6657
The
native async trait
in Rust has a limitation where it requires explicit declaration if it implements the Send or non-Send version of a trait.For instance, consider the following trait:
This desugars to:
By default, the returned Future does not have the Send bound, which is necessary for a multithreaded runtime. Without using
trait_variant
to create a multithreaded version of the trait, we encounter errors as below indicating that the future cannot be sent between threads safely.For more details on this issue, refer to the following resources:
https://blog.rust-lang.org/inside-rust/2023/05/03/stabilizing-async-fn-in-trait.html#mvp-part-2-send-bounds-and-associated-return-types
https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html#async-fn-in-public-traits
On the other hand, by utilizing the
#[async_trait]
attribute, async functions are transformed into methods that returnPin<Box<dyn Future + Send + 'async_trait>>
. This results in a Future that is thread-safe by default.