Skip to main content

Crate dolang_rpc

Crate dolang_rpc 

Source
Expand description

Framed, multiplexed RPC sessions over asynchronous byte streams.

Define a Protocol, negotiate a transport with Builder, then bind the negotiated endpoint to that protocol. The client may issue concurrent calls; Server::serve dispatches concurrent request handlers.

use dolang_rpc::{Builder, Protocol, server::CallContext};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
enum Request { Ping }
#[derive(Deserialize, Serialize)]
enum Response { Pong }
struct Example;
impl Protocol for Example {
    type Request = Request;
    type Response = Response;
}

async fn run() -> Result<(), Box<dyn std::error::Error>> {
    let (client_io, server_io) = tokio::io::duplex(16 * 1024);
    let (client, server) = tokio::try_join!(
        Builder::new("example", &[1]).client(client_io),
        Builder::new("example", &[1]).server(server_io),
    )?;

    let server = async {
        server.bind::<Example>().serve(async |mut context: CallContext<Example>, request| {
            context.shutdown();
            match request {
                Request::Ping => context.respond(Response::Pong),
            }
        }).await
    };
    let client = async {
        let response = client.bind::<Example>().call(Request::Ping).await?.into_response();
        assert!(matches!(response, Response::Pong));
        Ok::<_, dolang_rpc::Error>(())
    };
    let (server, client) = tokio::join!(server, client);
    server?;
    client?;
    Ok(())
}

Modules§

auth
Optional shared secret authentication.
client
The calling side of a bound RPC session.
handle
Native operating-system handles attached directly to RPC messages.
server
The handling side of a bound RPC session.
session
Session-scoped opaque handles.
trailer
Streaming request or response byte trailers.

Structs§

Builder
Builds an unbound client or server endpoint.

Enums§

Error
An error from session establishment, transport, or an individual call.

Traits§

Protocol
A family of messages exchanged by one RPC session.