feat!: relax request impls to be generic to any mailbox #71
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.
This PR relaxes the implementation of the mailbox for the following traits:
MessageSend
::send
TryMessageSend
::try_send
BlockingMessageSend
::blocking_send
TryBlockingMessageSend
::try_blocking_send
Previously, sending a message to a generic actor reference required explicitly specifying the mailbox type:
To resolve this, the mailbox had to be declared as
A: Actor<Mailbox = BoundedMailbox<A>>
. However, this restricted flexibility when we wanted to support both bounded and unbounded mailboxes.With this PR, this code will now work seamlessly, as the
MessageSend::send
method is now generic over any mailbox type. There's no longer a need to specify the mailbox. The only method that still requires a specified mailbox issend_sync
, which is only applicable for unbounded tell requests.The
Message
trait now requiresT
to implementSend + 'static
. This is necessary because sending a message to an actor requires these bounds. Without this constraint, if a user writesA: Actor + Message<M>
but forgets to specifyM: Send + 'static
, they'll encounter issues when messaging the actor, and the resulting error message won't clearly indicate what's missing.Before this PR, specifying a generic actor capable of handling a message required a complex and verbose trait bound like this:
You needed separate bounds for each message type, and for both tell and ask requests, which made the code unnecessarily verbose. This PR significantly improves the developer experience by simplifying these trait bounds, making Kameo much more ergonomic to use.
A nice resource for checking which requests types are supported when can be found here: https://docs.page/tqwewe/kameo/core-concepts/requests#request-methods
This PR fixes and relates to this discussion: #38