lrpc/
lib.rs

1//! Use tcp to call functions synchronously between processes
2//!
3//! # Examples
4//!
5//! ```no_run
6//! use lrpc::*;
7//!
8//! #[derive(CommonStore, Debug)]
9//! struct Point(i32, i32);
10//!
11//! #[derive(CommonStore, Debug)]
12//! struct Circle {
13//!     center: Point,
14//!     radius: u32,
15//! }
16//!
17//! #[fmt_function]
18//! fn new_circle(p: Point, r: u32) -> Circle {
19//!     Circle {
20//!         center: p,
21//!         radius: r,
22//!     }
23//! }
24//!
25//! #[fmt_function]
26//! fn circle_area(c: Circle) -> f64 {
27//!     let f_radius = c.radius as f64;
28//!     f_radius * f_radius * 3.14159
29//! }
30//!
31//! fn main() {
32//!     let mut srv_fun = Fun::new();
33//!     srv_fun.regist("new_circle", new_circle);
34//!     srv_fun.regist("circle_area", circle_area);
35//!
36//!     //start service
37//!     std::thread::spawn(move || {
38//!         service(srv_fun, "0.0.0.0:9009");
39//!     });
40//!     std::thread::sleep(std::time::Duration::from_millis(10));
41//!
42//!     let mut conn = Connection::new("127.0.0.1:9009");
43//!     let circle: Result<Circle> = conn.invoke(fun!("new_circle", Point(400, 300), 100));
44//!     if let Ok(circle) = circle {
45//!         println!("{:?}", circle);
46//!         let area: Result<f64> = conn.invoke(fun!("circle_area", circle));
47//!         println!("{:?}", area);
48//!     }
49//! }
50//! ```
51
52mod val;
53pub use val::{ByteQue, Store};
54#[macro_use]
55mod fun;
56pub use fun::{Fun, Result};
57pub use lrpc_macros::{fmt_function, CommonStore};
58mod buf;
59pub use buf::{send_data, RecvBuf};
60mod tcp;
61pub use tcp::{service, Connection};
62
63#[cfg(test)]
64mod tests;