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, transport::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::transport::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

RpcClient and support types
Traits to define the behaviour of messages for services
RpcServer and support types
Transports for quic-rpc

Macros

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

Enums

The kinds of local addresses a ServerChannel can be bound to.

Traits

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