Expand description
§tarpc-cat
RPC framework built on comp-cat-rs.
Wraps TCP networking with lazy, composable effects. All operations
return Io<Error, A> and nothing executes until .run().
§Quick start
Define a service:
ⓘ
use tarpc_cat::serve::Serve;
use tarpc_cat::error::Error;
use comp_cat_rs::effect::io::Io;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct Ping(String);
#[derive(Serialize, Deserialize)]
struct Pong(String);
#[derive(Clone)]
struct PingService;
impl Serve for PingService {
type Request = Ping;
type Response = Pong;
fn handle(&self, request: Ping) -> Io<Error, Pong> {
Io::pure(Pong(request.0))
}
}Run the server:
ⓘ
use tarpc_cat::server::{serve, ListenAddr};
let addr = ListenAddr::new("127.0.0.1:9000".parse().unwrap());
serve(addr, PingService).run()?;Call from a client:
ⓘ
use tarpc_cat::client::{call, ServerAddr};
let addr = ServerAddr::new("127.0.0.1:9000".parse().unwrap());
let pong: Pong = call(addr, Ping("hello".into())).run()?;Modules§
- client
- RPC client for calling remote services.
- codec
- Length-delimited framing over
Read/Write. - error
- Project-wide error type.
- protocol
- Wire protocol types.
- serve
- Service trait for defining RPC handlers.
- server
- RPC server that accepts connections and dispatches to a
Servehandler. - transport
- Transport abstraction for sending and receiving envelopes.