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