blob: bfa5a696d6ec1e4b274e91629b3f1247f7083fe6 (
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
|
#[tokio::test]
async fn test_hello_service() {
#[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}!"))
}
}
let listener = urpc::unix::bind("./hello.service").await.unwrap();
// spawn the server
tokio::spawn(async move {
urpc::Server::default()
.with_listener(listener)
.with_service(HelloServer.into_service())
.serve()
.await
});
// create a client
let channel = urpc::ClientChannel::new(urpc::unix::connect("./hello.service").await.unwrap());
let client = HelloClient::new(channel);
let greeting = client.hello("World".into()).await.unwrap();
assert_eq!(greeting, "Hello, World!");
}
|