use futures::prelude::*;
use lrcall::server::{self, Channel};
use lrcall::{client, context};
#[lrcall::service]
pub trait World {
async fn hello(name: String) -> String;
}
#[derive(Clone)]
struct HelloService;
impl World for HelloService {
async fn hello(self, _: context::Context, name: String) -> String {
format!("Hello, {name}!")
}
}
async fn spawn(fut: impl Future<Output = ()> + Send + 'static) {
tokio::spawn(fut);
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let (client_transport, server_transport) = lrcall::transport::channel::unbounded();
let server = server::BaseChannel::with_defaults(server_transport);
tokio::spawn(server.execute(HelloService.serve()).for_each(spawn));
let client = WorldClient::<HelloService>::rpc_client((client::Config::default(), client_transport).into());
let hello = client.hello(context::rpc_current(), "Andeya".to_string()).await?;
println!("{hello}");
Ok(())
}