refactor: Add associated types to Service
, use protocol enum as Service
#48
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.
Based on #47 (can rebase on main if needed)
Alternative to #41
Fixes #39
This PR tries to simplify working with irpc with these changes:
Added two associated types to the
Service
trait to point to the raw request enum (usually calledXxxProtocol
) and the message enum where the variants contain theWithChannels
structs (usually calledXxxMessage
). By doing this, we can reduce the generics on theClient
from 3 to 1, and on theLocalSender
from 2 to 1. I think this is a net benefit for all users.Instead of defining a separate
Service
struct, we can simply use theXxxProtocol
struct as the service! One type less to define and manage.The service trait is now implemented by the proc macro. It is still possible to set a
service = SomeType
arg if, for some reason, you'd want the service to be separate from the protocol enum type.The proc macro's first and required argument is now the name of the message type. With the proc macro now implementing the serivce trait, and the service trait having an associated type for the message enum, I found it easiest to make the message enum creation non-optional. Also so far I never had a use case for the derive macro not creating the message enum. Do others? If not I think this is the simplest. Can also change it to be optional again though.
First and foremost, have a look at the diff to the examples.