dispatch_call

Function dispatch_call 

Source
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>>
where A: Facet<'static> + Send, R: Facet<'static> + Send, E: Facet<'static> + Send, F: FnOnce(A) -> Fut + Send + 'static, Fut: Future<Output = Result<R, E>> + Send + 'static,
Expand description

Helper for dispatching RPC methods with minimal generated code.

This function handles the common dispatch pattern:

  1. Deserialize args from payload
  2. Bind any Tx/Rx streams via registry
  3. Call the handler closure
  4. 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 type
  • Fut: 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.