-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Description
I added the service trait as a scope for the additional data that you add to a request type.
The purpose of this is so you can use the same message in different services. See example below. GetRequest and PutRequest are used both for the user facing service and some internal service, and I could even define different response stream items or types for each message.
I originally thought that this might be useful, e.g. if your request types are from another crate, and you don't want to newtype them. But so far I have never actually done this.
WDYT @Frando ? Should we remove it and make things simpler, or are they worth it?
use external_crate::{GetRequest, PutRequest};
struct KvService;
impl Service for KvService;
#[rpc_requests(KvService, message = RequestWithChannels)]
#[derive(Serialize, Deserialize)]
enum Request {
#[rpc(tx=oneshot::Sender<String>)]
Get(GetRequest),
#[rpc(tx=oneshot::Sender<()>)]
Put(PutRequest),
}
struct InternalService;
impl Service for InternalService;
#[rpc_requests(InternalService, message = InternalRequestWithChannels)]
#[derive(Serialize, Deserialize)]
enum InternalRequest {
#[rpc(tx=oneshot::Sender<String>)]
Get(GetRequest),
#[rpc(tx=oneshot::Sender<()>)]
Put(PutRequest),
}Metadata
Metadata
Assignees
Labels
No labels