pub fn dispatch_call<A, R, E, F, Fut>(
cx: &Context,
payload: Vec<u8>,
registry: &mut ChannelRegistry,
handler: F,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>Expand description
Helper for dispatching RPC methods with minimal generated code.
This function handles the common dispatch pattern:
- Deserialize args from payload
- Bind any Tx/Rx streams via registry
- Call the handler closure
- Encode the result and send Response
The generated code just needs to provide a closure that calls the handler method.
§Type Parameters
A: Args tuple type (must implement Facet for deserialization)R: Result ok type (must implement Facet for serialization)E: User error type (must implement Facet for serialization)F: Handler closure typeFut: Future returned by handler
§Example
ⓘ
fn dispatch_echo(&self, payload: Vec<u8>, request_id: u64, registry: &mut ChannelRegistry)
-> Pin<Box<dyn Future<Output = ()> + Send + 'static>>
{
let handler = self.handler.clone();
dispatch_call(payload, request_id, registry, move |args: (String,)| async move {
handler.echo(args.0).await
})
}The handler returns Result<R, E> - user errors are automatically wrapped
in RoamError::User(e) for wire serialization.
The channels parameter contains channel IDs from the Request message framing.
These are patched into the deserialized args before binding streams.