Crate quic_rpc

source ·
Expand description

A streaming rpc system based on quic

Motivation

See the README

Example

use quic_rpc::{message::RpcMsg, Service, RpcClient, mem::MemChannelTypes};
use serde::{Serialize, Deserialize};
use derive_more::{From, TryInto};

// Define your messages
#[derive(Debug, Serialize, Deserialize)]
struct Ping;

#[derive(Debug, Serialize, Deserialize)]
struct Pong;

// Define your RPC service and its request/response types

#[derive(Debug, Serialize, Deserialize, From, TryInto)]
enum PingRequest {
    Ping(Ping),
}

#[derive(Debug, Serialize, Deserialize, From, TryInto)]
enum PingResponse {
    Pong(Pong),
}

#[derive(Debug, Clone)]
struct PingService;

impl Service for PingService {
  type Req = PingRequest;
  type Res = PingResponse;
}

// Define interaction patterns for each request type
impl RpcMsg<PingService> for Ping {
  type Response = Pong;
}

// create a transport channel
let (server, client) = quic_rpc::mem::connection::<PingRequest, PingResponse>(1);

// create the rpc client given the channel and the service type
let mut client = RpcClient::<PingService, MemChannelTypes>::new(client);

// call the service
let res = client.rpc(Ping).await?;

Re-exports

pub use client::RpcClient;
pub use server::RpcServer;

Modules

Generic channel factory, and some implementations
RpcClient and support types
Channel that combines two other channels
Macros to reduce boilerplate for RPC implementations.
Memory channel implementation
Traits to define the behaviour of messages for services
QUIC channel implementation based on quinn
RpcServer and support types

Macros

Derive a set of RPC types and message implementation from a declaration.

Traits

An abstract channel with typed input and output
Defines a set of types for a kind of channel
requirements for an internal error
requirements for a RPC message
A service