RpcRequest

Trait RpcRequest 

Source
pub trait RpcRequest:
    ProstMessage
    + Default
    + Send
    + Sync
    + 'static {
    type Response: ProstMessage + Default + Send + Sync + 'static;

    // Required method
    fn route_key() -> &'static str;

    // Provided method
    fn payload_type() -> PayloadType { ... }
}
Expand description

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

This trait is only implemented for RPC request messages, not for:

  • RPC response messages (EchoResponse, etc.)
  • Streaming data (StreamChunk, MediaFrame)
  • Other protobuf messages

§Type Safety

The RpcRequest trait enables the framework to provide compile-time guarantees that:

  • The correct response type is used when decoding RPC responses
  • Type inference works seamlessly for ctx.call<R: RpcRequest>(...) APIs
  • Mismatched request/response pairs are caught at compile time

§Example

use actr_protocol::RpcRequest;
use prost::Message as ProstMessage;

#[derive(Clone, PartialEq, ProstMessage)]
pub struct EchoRequest {
    #[prost(string, tag = "1")]
    pub message: String,
}

#[derive(Clone, PartialEq, ProstMessage)]
pub struct EchoResponse {
    #[prost(string, tag = "1")]
    pub reply: String,
}

// Generated by actr-cli codegen
impl RpcRequest for EchoRequest {
    type Response = EchoResponse;
}

§Usage in Client Code

use actr_framework::Context;

async fn call_echo_service<C: Context>(
    ctx: &C,
    target: &Dest,
    message: String
) -> ActorResult<String> {
    let request = EchoRequest { message };

    // Type inference: compiler knows Response = EchoResponse
    let response = ctx.call(target, request).await?;

    Ok(response.reply)
}

Required Associated Types§

Source

type Response: ProstMessage + Default + Send + Sync + 'static

The response type associated with this RPC request.

This associated type enables compile-time type checking of request/response pairs. When calling ctx.call::<R>(...), the framework automatically decodes the response bytes into R::Response.

Required Methods§

Source

fn route_key() -> &'static str

Returns the route key for this RPC method.

The route key identifies the specific RPC method to invoke, typically in the format “package.Service.Method” (e.g., “echo.EchoService.Echo”).

This method is used by the framework to automatically populate the RpcEnvelope’s route_key field when making type-safe RPC calls.

Provided Methods§

Source

fn payload_type() -> PayloadType

Returns the PayloadType for this RPC method.

The PayloadType determines the transmission characteristics (reliable vs. signal) and is declared in the protobuf service definition:

rpc KickUser(KickRequest) returns (KickResponse) {
    option (actr.payload_type) = RPC_SIGNAL;
}

If not specified, defaults to PayloadType::RpcReliable.

This method is used by the framework to select the appropriate transmission lane when making RPC calls.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§