Module message

Module message 

Source
Expand description

RpcRequest trait for type-safe RPC calls

This module defines the RpcRequest trait which associates RPC Request types with their corresponding Response types. This enables compile-time type safety for client-side RPC calls through type inference.

§Design Rationale

Without the RpcRequest trait, client code must manually:

  1. Encode the request into bytes
  2. Specify the route_key as a string (prone to typos)
  3. Manually decode the response (can use wrong type)

With the RpcRequest trait, the framework can provide type-safe APIs:

// Type-safe: compiler infers EchoResponse from EchoRequest::Response
let response: EchoResponse = ctx.call(target, request).await?;

§Implementation

The RpcRequest trait is implemented by the code generator for each protobuf message that represents an RPC request:

impl RpcRequest for EchoRequest {
    type Response = EchoResponse;
}

§Placement in actr-protocol

This trait is placed in actr-protocol (not actr-framework) because:

  • It’s a pure type-level association with no async methods
  • It only depends on prost::Message and standard traits
  • It can be independently tested without runtime dependencies
  • It follows the “data definition layer” principle of actr-protocol

Traits§

RpcRequest
Associates an RPC Request type with its Response type for type-safe RPC calls.