Docs.rs
  • quic-rpc-0.18.2
    • quic-rpc 0.18.2
    • Docs.rs crate page
    • Apache-2.0/MIT
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • dignifiedquire
    • rklaehn
    • github:n0-computer:iroh-maintainers
    • Dependencies
      • anyhow ^1 normal
      • bytes ^1 normal optional
      • document-features ^0.2 normal
      • flume ^0.11 normal optional
      • futures ^0.3.30 normal optional
      • futures-lite ^2.3.0 normal
      • futures-sink ^0.3.30 normal
      • futures-util ^0.3.30 normal
      • hyper ^0.14.16 normal optional
      • iroh ^0.33 normal optional
      • pin-project ^1 normal
      • postcard ^1 normal optional
      • iroh-quinn ^0.13 normal optional
      • rcgen ^0.13 normal optional
      • rustls ^0.23 normal optional
      • serde ^1 normal
      • slab ^0.4.9 normal
      • smallvec ^1.13.2 normal
      • time ^0.3.36 normal
      • tokio ^1 normal
      • tokio-serde ^0.9 normal optional
      • tokio-util ^0.7 normal
      • tracing ^0.1 normal
      • anyhow ^1 dev
      • async-stream ^0.3.3 dev
      • derive_more ^1 dev
      • futures-buffered ^0.2.4 dev
      • nested_enum_utils ^0.1.0 dev
      • proc-macro2 ^1.0.66 dev
      • iroh-quinn ^0.13 dev
      • rand ^0.8 dev
      • rcgen ^0.13 dev
      • serde ^1 dev
      • tempfile ^3.5.0 dev
      • testresult ^0.4.1 dev
      • thousands ^0.2.0 dev
      • tokio ^1 dev
      • tokio-util ^0.7 dev
      • tracing-subscriber ^0.3.16 dev
    • Versions
    • 100% of the crate is documented
  • Go to latest version
  • Platform
    • i686-unknown-linux-gnu
    • x86_64-unknown-linux-gnu
  • Feature flags
  • Rust
    • About docs.rs
    • Privacy policy
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate quic_rpc

quic_rpc0.18.2

  • All Items

Sections

  • Motivation
  • Example
  • Features

Crate Items

  • Re-exports
  • Modules
  • Macros
  • Traits
  • Functions

Crates

  • quic_rpc

Crate quic_rpc

Source
Expand description

A streaming rpc system for transports that support multiple bidirectional streams, such as QUIC and HTTP2.

A lightweight memory transport is provided for cases where you want have multiple cleanly separated substreams in the same process.

For supported transports, see the transport module.

§Motivation

See the README

§Example

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

// 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, Clone)]
struct PingService;

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

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

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, here a memory channel for testing
let (server, client) = quic_rpc::transport::flume::channel(1);

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

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

// server side
// create the rpc server given the channel and the service type
let mut server = RpcServer::<PingService, _>::new(server);

let handler = Handler;
loop {
    // accept connections
    let (msg, chan) = server.accept().await?.read_first().await?;
    // dispatch the message to the appropriate handler
    match msg {
        PingRequest::Ping(ping) => chan.rpc(ping, handler, Handler::ping).await?,
    }
}

// the handler. For a more complex example, this would contain any state
// needed to handle the request.
#[derive(Debug, Clone, Copy)]
struct Handler;

impl Handler {
    // the handle fn for a Ping request.

    // The return type is the response type for the service.
    // Note that this must take self by value, not by reference.
    async fn ping(self, _req: Ping) -> Pong {
        Pong
    }
}

§Features

  • hyper-transport — HTTP transport using the hyper crate
  • quinn-transport — QUIC transport using the iroh-quinn crate
  • flume-transport (enabled by default) — In memory transport using the flume crate
  • iroh-transport — p2p QUIC transport using the iroh crate
  • macros — Macros for creating request handlers
  • test-utils — Utilities for testing
  • default — Default, includes the memory transport

Re-exports§

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

Modules§

client
Client side api
message
Service definition
pattern
Predefined interaction patterns.
server
Server side api
transport
Built in transports for quic-rpc

Macros§

declare_bidi_streamingmacros
Declare a message to be a server streaming message for a service.
declare_client_streamingmacros
Declare a message to be a server streaming message for a service.
declare_rpcmacros
Declare a message to be a rpc message for a service.
declare_server_streamingmacros
Declare a message to be a server streaming message for a service.
rpc_servicemacros
Derive a set of RPC types and message implementation from a declaration.

Traits§

Connector
A connector to a specific service
Listener
A listener for a specific service
RpcError
Requirements for an internal error
RpcMessage
Requirements for a RPC message
Service
A service

Functions§

flume_channelflume-transport
Create a pair of RpcServer and RpcClient for the given Service type using a flume channel
quinn_channeltest-utils
Create a pair of RpcServer and RpcClient for the given Service type using a quinn channel

Results

Settings
Help
    trait
    quic_rpc::pattern::server_streaming::ServerStreamingMsg
    Defines response type for a server streaming message.
    trait
    quic_rpc::pattern::try_server_streaming::TryServerStreamingMsg
    Same as ServerStreamingMsg, but with lazy stream creation …
    method
    quic_rpc::client::RpcClient::server_streaming
    &RpcClient<S, C>, M -> Result<BoxStreamSync<Result<ItemError<C>>>, Error<C>>
    where
    M: ServerStreamingMsg<S>
    Bidi call to the server, request opens a stream, response …
    method
    quic_rpc::server::RpcChannel::server_streaming
    RpcChannel<S, C>, M, T, F -> Result<(), RpcServerError<C>>
    where
    M: ServerStreamingMsg<S>
    handle the message M using the given function on the …
No results :(
Try on DuckDuckGo?

Or try looking in one of these:
  • The Rust Reference for technical details about the language.
  • Rust By Example for expository code examples.
  • The Rust Book for introductions to language features and the language itself.
  • Docs.rs for documentation of crates released on crates.io.