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
'staticbound from theAsynctrait, which was originally an alias toSend + Sync + 'static.The
Asynctrait 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 theSendbound 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 + Synctrait 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 + Syncbounds for them to be usable inside async code. Originally, the'staticbound was also included, as it was also common for async code to also require'staticbound when spawning async tasks.The
Asynctrait is introduced as a helper trait, so that users can use it instead of writingSend + Synceverywhere. Originally, the'staticbound was also included, as it is common for async code to also require'staticwhen 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
'staticinsideAsyncby 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 + Syncis 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, theAsynctrait itself can entirely be deprecated or removed.However, until RTN is stabilized, we still need
Asynctrait with only theSend + Syncbounds. It is also unclear when RTN will actually gets stabilized, and whether we will be able to completely removeAsyncby then. Hence, at the very least, it is better to remove'staticfromAsyncin case ifAsynclingers longer than we expect.