• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /// The request message containing the user's name.
2 #[derive(Clone, PartialEq, ::prost::Message)]
3 pub struct HelloRequest {
4     #[prost(string, tag = "1")]
5     pub name: std::string::String,
6 }
7 /// The response message containing the greetings
8 #[derive(Clone, PartialEq, ::prost::Message)]
9 pub struct HelloReply {
10     #[prost(string, tag = "1")]
11     pub message: std::string::String,
12 }
13 #[doc = r" Generated client implementations."]
14 pub mod client {
15     #![allow(unused_variables, dead_code, missing_docs)]
16     use tonic::codegen::*;
17     #[doc = " The greeting service definition."]
18     pub struct GreeterClient<T> {
19         inner: tonic::client::Grpc<T>,
20     }
21     impl GreeterClient<tonic::transport::Channel> {
22         #[doc = r" Attempt to create a new client by connecting to a given endpoint."]
connect<D>(dst: D) -> Result<Self, tonic::transport::Error> where D: TryInto<tonic::transport::Endpoint>, D::Error: Into<StdError>,23         pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
24         where
25             D: TryInto<tonic::transport::Endpoint>,
26             D::Error: Into<StdError>,
27         {
28             let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
29             Ok(Self::new(conn))
30         }
31     }
32     impl<T> GreeterClient<T>
33     where
34         T: tonic::client::GrpcService<tonic::body::BoxBody>,
35         T::ResponseBody: Body + Send + 'static,
36         T::Error: Into<StdError>,
37         <T::ResponseBody as Body>::Error: Into<StdError> + Send,
38         <T::ResponseBody as Body>::Data: Into<bytes::Bytes> + Send,
39     {
new(inner: T) -> Self40         pub fn new(inner: T) -> Self {
41             let inner = tonic::client::Grpc::new(inner);
42             Self { inner }
43         }
44         #[doc = r" Check if the service is ready."]
ready(&mut self) -> Result<(), tonic::Status>45         pub async fn ready(&mut self) -> Result<(), tonic::Status> {
46             self.inner.ready().await.map_err(|e| {
47                 tonic::Status::new(
48                     tonic::Code::Unknown,
49                     format!("Service was not ready: {}", e.into()),
50                 )
51             })
52         }
53         #[doc = " Sends a greeting"]
say_hello( &mut self, request: tonic::Request<super::HelloRequest>, ) -> Result<tonic::Response<super::HelloReply>, tonic::Status>54         pub async fn say_hello(
55             &mut self,
56             request: tonic::Request<super::HelloRequest>,
57         ) -> Result<tonic::Response<super::HelloReply>, tonic::Status> {
58             self.ready().await?;
59             let codec = tonic::codec::ProstCodec::default();
60             let path = http::uri::PathAndQuery::from_static("/helloworld.Greeter/SayHello");
61             self.inner.unary(request, path, codec).await
62         }
63     }
64     impl<T: Clone> Clone for GreeterClient<T> {
clone(&self) -> Self65         fn clone(&self) -> Self {
66             Self {
67                 inner: self.inner.clone(),
68             }
69         }
70     }
71 }
72 #[doc = r" Generated server implementations."]
73 pub mod server {
74     #![allow(unused_variables, dead_code, missing_docs)]
75     use tonic::codegen::*;
76     #[doc = "Generated trait containing gRPC methods that should be implemented for use with GreeterServer."]
77     #[async_trait]
78     pub trait Greeter: Send + Sync + 'static {
79         #[doc = " Sends a greeting"]
say_hello( &self, request: tonic::Request<super::HelloRequest>, ) -> Result<tonic::Response<super::HelloReply>, tonic::Status>80         async fn say_hello(
81             &self,
82             request: tonic::Request<super::HelloRequest>,
83         ) -> Result<tonic::Response<super::HelloReply>, tonic::Status> {
84             Err(tonic::Status::unimplemented("Not yet implemented"))
85         }
86     }
87     #[doc = " The greeting service definition."]
88     #[derive(Clone, Debug)]
89     pub struct GreeterServer<T: Greeter> {
90         inner: Arc<T>,
91     }
92     #[derive(Clone, Debug)]
93     #[doc(hidden)]
94     pub struct GreeterServerSvc<T: Greeter> {
95         inner: Arc<T>,
96     }
97     impl<T: Greeter> GreeterServer<T> {
98         #[doc = "Create a new GreeterServer from a type that implements Greeter."]
new(inner: T) -> Self99         pub fn new(inner: T) -> Self {
100             let inner = Arc::new(inner);
101             Self::from_shared(inner)
102         }
from_shared(inner: Arc<T>) -> Self103         pub fn from_shared(inner: Arc<T>) -> Self {
104             Self { inner }
105         }
106     }
107     impl<T: Greeter> GreeterServerSvc<T> {
new(inner: Arc<T>) -> Self108         pub fn new(inner: Arc<T>) -> Self {
109             Self { inner }
110         }
111     }
112     impl<T: Greeter, R> Service<R> for GreeterServer<T> {
113         type Response = GreeterServerSvc<T>;
114         type Error = Never;
115         type Future = Ready<Result<Self::Response, Self::Error>>;
poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>116         fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
117             Poll::Ready(Ok(()))
118         }
call(&mut self, _: R) -> Self::Future119         fn call(&mut self, _: R) -> Self::Future {
120             ok(GreeterServerSvc::new(self.inner.clone()))
121         }
122     }
123     impl<T: Greeter> Service<http::Request<HyperBody>> for GreeterServerSvc<T> {
124         type Response = http::Response<tonic::body::BoxBody>;
125         type Error = Never;
126         type Future = BoxFuture<Self::Response, Self::Error>;
poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>127         fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
128             Poll::Ready(Ok(()))
129         }
call(&mut self, req: http::Request<HyperBody>) -> Self::Future130         fn call(&mut self, req: http::Request<HyperBody>) -> Self::Future {
131             let inner = self.inner.clone();
132             match req.uri().path() {
133                 "/helloworld.Greeter/SayHello" => {
134                     struct SayHello<T: Greeter>(pub Arc<T>);
135                     impl<T: Greeter> tonic::server::UnaryService<super::HelloRequest> for SayHello<T> {
136                         type Response = super::HelloReply;
137                         type Future = BoxFuture<tonic::Response<Self::Response>, tonic::Status>;
138                         fn call(
139                             &mut self,
140                             request: tonic::Request<super::HelloRequest>,
141                         ) -> Self::Future {
142                             let inner = Arc::clone(&self.0);
143                             let fut = async move { inner.say_hello(request).await };
144                             Box::pin(fut)
145                         }
146                     }
147                     let inner = self.inner.clone();
148                     let fut = async move {
149                         let method = SayHello(inner);
150                         let codec = tonic::codec::ProstCodec::default();
151                         let mut grpc = tonic::server::Grpc::new(codec);
152                         let res = grpc.unary(method, req).await;
153                         Ok(res)
154                     };
155                     Box::pin(fut)
156                 }
157                 _ => Box::pin(async move {
158                     Ok(http::Response::builder()
159                         .status(200)
160                         .header("grpc-status", "12")
161                         .body(empty_body())
162                         .unwrap())
163                 }),
164             }
165         }
166     }
167 }
168