Runtime

The yellow and blue parts are called "norpc runtime".

As mentioned in the earlier section, the code generated by the compiler (in red) are runtime-agnostic.

To run the service on a runtime, you need to implement the trait generated by the compiler.


#![allow(unused_variables)]
fn main() {
struct HelloWorldApp;
#[async_trait::async_trait]
impl HelloWorld for HelloWorldApp {
    async fn hello(&self, s: String) -> String {
        format!("Hello, {}", s)
    }
}
}

And then you can build a server and a channel. After spawning the server on a async runtime, you can send requests to the server through the channel. Note that the server is async runtime agnostic so you can choose any async runtime to execute the server.


#![allow(unused_variables)]
fn main() {
use norpc::runtime::*;
let app = HelloWorldApp;
let builder = ServerBuilder::new(HelloWorldService::new(app));
let (chan, server) = builder.build();

tokio::spawn(server.serve(TokioExecutor));

let mut cli = HelloWorldClient::new(chan);
assert_eq!(cli.hello("World".to_owned()).await, "Hello, World");
}