n0-computer / quic-rpc

A streaming rpc system based on quic
Other
94 stars 12 forks source link

feat: Allow to compose RPC services #67

Closed Frando closed 7 months ago

Frando commented 7 months ago

It was quite a ride through the generics in this crate, but I finally found a solution for how to nicely decouple RPC services between modules or crates.

Importantly, it allows for an outer, app-level RPC service to delegate to inner services which are defined in other modules or crates. The inner services are regular quic-rpc services, and can even run on their own without the outer service. They take a single additional generic, so the code does not become horribly more generic.

See the modularize example for a full, end-to-end example that composes RPC services from two different modules (which could be crates as well).

Edit I found a new approach that allows to compose services not only for two layers but infinitely. I updated the modularize example to have an additonal layer:

Note that the composition works equally for the server handler and a client wrapper. See the example.