/// The request message containing the user's name. #[derive(Clone, PartialEq, ::prost::Message)] pub struct HelloRequest { #[prost(string, tag = "1")] pub name: std::string::String, } /// The response message containing the greetings #[derive(Clone, PartialEq, ::prost::Message)] pub struct HelloReply { #[prost(string, tag = "1")] pub message: std::string::String, } use tonic::_codegen::*; #[async_trait] pub trait Greeter: Send + Sync + 'static { async fn say_hello( &self, request: tonic::Request, ) -> Result, tonic::Status>; } #[derive(Clone)] pub struct GreeterServer { inner: std::sync::Arc, } pub struct GreeterServerSvc { inner: std::sync::Arc, } impl GreeterServer { pub fn new(inner: T) -> Self { let inner = std::sync::Arc::new(inner); Self { inner } } } impl GreeterServerSvc { pub fn new(inner: std::sync::Arc) -> Self { Self { inner } } } impl Service for GreeterServer { type Response = GreeterServerSvc; type Error = tonic::error::Never; type Future = Ready>; fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, _: R) -> Self::Future { ok(GreeterServerSvc::new(self.inner.clone())) } } impl Service> for GreeterServerSvc { type Response = http::Response; type Error = tonic::error::Never; type Future = BoxFuture; fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { Poll::Ready(Ok(())) } fn call(&mut self, req: http::Request) -> Self::Future { let inner = self.inner.clone(); match req.uri().path() { "/helloworld.Greeter/SayHello" => { struct SayHello(pub std::sync::Arc); impl tonic::server::UnaryService for SayHello { type Response = self::HelloReply; type Future = BoxFuture, tonic::Status>; fn call( &mut self, request: tonic::Request, ) -> Self::Future { let inner = self.0.clone(); let fut = async move { inner.say_hello(request).await }; Box::pin(fut) } } let inner = self.inner.clone(); let fut = async move { let method = SayHello(inner); let codec = tonic::codec::ProstCodec::new(); let mut grpc = tonic::server::Grpc::new(codec); let res = grpc.unary(method, req).await; Ok(res) }; Box::pin(fut) } _ => unimplemented!("use grpc unimplemented"), } } } use tonic::_codegen::*; pub struct GreeterClient { inner: tonic::client::Grpc, } impl GreeterClient where T: tonic::client::GrpcService, T::ResponseBody: tonic::body::Body + tonic::_codegen::HttpBody + Send + 'static, T::Error: Into, ::Error: Into + Send, ::Data: Into + Send, { pub fn new(inner: T) -> Self { let inner = tonic::client::Grpc::new(inner); Self { inner } } pub async fn ready(&mut self) -> Result<(), tonic::Status> { self.inner.ready().await.map_err(|e| { tonic::Status::new( tonic::Code::Unknown, format!("Service was not ready: {}", e.into()), ) }) } pub async fn say_hello( &mut self, request: tonic::Request, ) -> Result, tonic::Status> { self.ready().await?; let codec = tonic::codec::ProstCodec::new(); let path = http::uri::PathAndQuery::from_static("/helloworld.Greeter/SayHello"); self.inner.unary(request, path, codec).await } } impl Clone for GreeterClient { fn clone(&self) -> Self { Self { inner: self.inner.clone(), } } }