Remove 'static
bound from Async
trait alias
#89
Merged
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.
Summary
This PR removes the
'static
bound from theAsync
trait, which was originally an alias toSend + Sync + 'static
.The
Async
trait is important for CGP code to more easily define abstract types that can be used more easily within async functions. Currently, it is necessary for async functions in traits to include at least theSend
bound in the returnedFuture
, in order for it to be usable in async executors such astokio::spawn
. This implies that almost all abstract types need to have at least theSend + Sync
trait bounds to be included.Although CGP makes it possible to add these bounds at the implementation site, it would quickly become overly tedious if we need to do this for almost every abstract type. As a result, CGP encourages abstract types to be define with
Send + Sync
bounds for them to be usable inside async code. Originally, the'static
bound was also included, as it was also common for async code to also require'static
bound when spawning async tasks.The
Async
trait is introduced as a helper trait, so that users can use it instead of writingSend + Sync
everywhere. Originally, the'static
bound was also included, as it is common for async code to also require'static
when spawning async tasks. However, in practice, the use is infrequent enough that we don't need to include that inside the default trait bound for all abstract types.Furthermore, the inclusion of
'static
insideAsync
by default makes it more challenging to instantiate abstract types with concrete types that contain non-static lifetimes. As the use of CGP grows, we want to avoid the default from making it almost impossible to use non-static concrete types with CGP. As a result, it is best to remove this before CGP gains wider adoption.On the other hand, the default inclusion of
Send + Sync
is almost a necessary evil with the current state of async Rust. However, this may soon change when Return Type Notation (RTN) gets stabilized in Rust in the near future in rust-lang/rust#138424. Once that is stabilized, theAsync
trait itself can entirely be deprecated or removed.However, until RTN is stabilized, we still need
Async
trait with only theSend + Sync
bounds. It is also unclear when RTN will actually gets stabilized, and whether we will be able to completely removeAsync
by then. Hence, at the very least, it is better to remove'static
fromAsync
in case ifAsync
lingers longer than we expect.