Skip to main content

tarpc_cat/
lib.rs

1//! # tarpc-cat
2//!
3//! RPC framework built on [`comp-cat-rs`](https://crates.io/crates/comp-cat-rs).
4//!
5//! Wraps TCP networking with lazy, composable effects.  All operations
6//! return [`Io<Error, A>`] and nothing executes until `.run()`.
7//!
8//! ## Quick start
9//!
10//! Define a service:
11//!
12//! ```rust,ignore
13//! use tarpc_cat::serve::Serve;
14//! use tarpc_cat::error::Error;
15//! use comp_cat_rs::effect::io::Io;
16//! use serde::{Serialize, Deserialize};
17//!
18//! #[derive(Serialize, Deserialize)]
19//! struct Ping(String);
20//!
21//! #[derive(Serialize, Deserialize)]
22//! struct Pong(String);
23//!
24//! #[derive(Clone)]
25//! struct PingService;
26//!
27//! impl Serve for PingService {
28//!     type Request = Ping;
29//!     type Response = Pong;
30//!
31//!     fn handle(&self, request: Ping) -> Io<Error, Pong> {
32//!         Io::pure(Pong(request.0))
33//!     }
34//! }
35//! ```
36//!
37//! Run the server:
38//!
39//! ```rust,ignore
40//! use tarpc_cat::server::{serve, ListenAddr};
41//!
42//! let addr = ListenAddr::new("127.0.0.1:9000".parse().unwrap());
43//! serve(addr, PingService).run()?;
44//! ```
45//!
46//! Call from a client:
47//!
48//! ```rust,ignore
49//! use tarpc_cat::client::{call, ServerAddr};
50//!
51//! let addr = ServerAddr::new("127.0.0.1:9000".parse().unwrap());
52//! let pong: Pong = call(addr, Ping("hello".into())).run()?;
53//! ```
54//!
55//! [`Io<Error, A>`]: comp_cat_rs::effect::io::Io
56
57pub mod client;
58pub mod codec;
59pub mod error;
60pub mod protocol;
61pub mod serve;
62pub mod server;
63pub mod transport;