blob: 6b84471dace4a9461367e66bcf05c0158361a22b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# urpc
A minimalistic RPC framework for Rust, designed for simplicity and performance.
## Features
- Async/await support
- TCP and Unix socket transport
- Procedural macros for service definitions
- Serialization with bincode
- Lightweight and fast
## Example
```rust
use urpc::*;
#[urpc::service]
trait Hello {
type Error = ();
async fn hello(name: String) -> String;
}
struct HelloServer;
impl Hello for HelloServer {
async fn hello(&self, _ctx: urpc::Context, name: String) -> Result<String, ()> {
Ok(format!("Hello, {}!", name))
}
}
#[tokio::main]
async fn main() {
// Server
let listener = urpc::tcp::bind("127.0.0.1:8080").await.unwrap();
tokio::spawn(async move {
urpc::Server::default()
.with_listener(listener)
.with_service(HelloServer.into_service())
.serve()
.await
});
// Client
let channel = urpc::ClientChannel::new(
urpc::tcp::connect("127.0.0.1:8080").await.unwrap()
);
let client = HelloClient::new(channel);
let response = client.hello("World".to_string()).await.unwrap();
println!("{}", response); // "Hello, World!"
}
```
## License
Licensed under either of
- Apache License, Version 2.0
- MIT License
at your option.
|