From b566d0c6460a3611f9ae385592ebd64d6c014652 Mon Sep 17 00:00:00 2001 From: Tim Kuehn Date: Sun, 26 Jul 2020 18:21:43 -0700 Subject: [PATCH] Use #[tarpc::server] in example-service --- example-service/src/server.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/example-service/src/server.rs b/example-service/src/server.rs index ac6d358..a6cdd1c 100644 --- a/example-service/src/server.rs +++ b/example-service/src/server.rs @@ -5,10 +5,7 @@ // https://opensource.org/licenses/MIT. use clap::{App, Arg}; -use futures::{ - future::{self, Ready}, - prelude::*, -}; +use futures::{future, prelude::*}; use service::World; use std::{ io, @@ -25,17 +22,10 @@ use tokio_serde::formats::Json; #[derive(Clone)] struct HelloServer(SocketAddr); +#[tarpc::server] impl World for HelloServer { - // Each defined rpc generates two items in the trait, a fn that serves the RPC, and - // an associated type representing the future output by the fn. - - type HelloFut = Ready; - - fn hello(self, _: context::Context, name: String) -> Self::HelloFut { - future::ready(format!( - "Hello, {}! You are connected from {:?}.", - name, self.0 - )) + async fn hello(self, _: context::Context, name: String) -> String { + format!("Hello, {}! You are connected from {:?}.", name, self.0) } }