pub struct Grpc<T> { /* private fields */ }
Expand description
A gRPC Server handler.
This will wrap some inner Codec
and provide utilities to handle
inbound unary, client side streaming, server side streaming, and
bi-directional streaming.
Each request handler method accepts some service that implements the
corresponding service trait and a http request that contains some body that
implements some Body
.
Implementations§
source§impl<T> Grpc<T>where
T: Codec,
impl<T> Grpc<T>where
T: Codec,
sourcepub fn accept_compressed(self, encoding: CompressionEncoding) -> Self
pub fn accept_compressed(self, encoding: CompressionEncoding) -> Self
Enable accepting compressed requests.
If a request with an unsupported encoding is received the server will respond with
Code::UnUnimplemented
.
Example
The most common way of using this is through a server generated by tonic-build:
#[tonic::async_trait]
impl Example for Svc {
// ...
}
let service = ExampleServer::new(Svc).accept_compressed(CompressionEncoding::Gzip);
sourcepub fn send_compressed(self, encoding: CompressionEncoding) -> Self
pub fn send_compressed(self, encoding: CompressionEncoding) -> Self
Enable sending compressed responses.
Requires the client to also support receiving compressed responses.
Example
The most common way of using this is through a server generated by tonic-build:
#[tonic::async_trait]
impl Example for Svc {
// ...
}
let service = ExampleServer::new(Svc).send_compressed(CompressionEncoding::Gzip);
sourcepub async fn unary<S, B>(
&mut self,
service: S,
req: Request<B>
) -> Response<BoxBody>where
S: UnaryService<T::Decode, Response = T::Encode>,
B: Body + Send + 'static,
B::Error: Into<Box<dyn Error + Send + Sync>> + Send,
pub async fn unary<S, B>(
&mut self,
service: S,
req: Request<B>
) -> Response<BoxBody>where
S: UnaryService<T::Decode, Response = T::Encode>,
B: Body + Send + 'static,
B::Error: Into<Box<dyn Error + Send + Sync>> + Send,
Handle a single unary gRPC request.
sourcepub async fn server_streaming<S, B>(
&mut self,
service: S,
req: Request<B>
) -> Response<BoxBody>where
S: ServerStreamingService<T::Decode, Response = T::Encode>,
S::ResponseStream: Send + 'static,
B: Body + Send + 'static,
B::Error: Into<Box<dyn Error + Send + Sync>> + Send,
pub async fn server_streaming<S, B>(
&mut self,
service: S,
req: Request<B>
) -> Response<BoxBody>where
S: ServerStreamingService<T::Decode, Response = T::Encode>,
S::ResponseStream: Send + 'static,
B: Body + Send + 'static,
B::Error: Into<Box<dyn Error + Send + Sync>> + Send,
Handle a server side streaming request.
sourcepub async fn client_streaming<S, B>(
&mut self,
service: S,
req: Request<B>
) -> Response<BoxBody>where
S: ClientStreamingService<T::Decode, Response = T::Encode>,
B: Body + Send + 'static,
B::Error: Into<Box<dyn Error + Send + Sync>> + Send + 'static,
pub async fn client_streaming<S, B>(
&mut self,
service: S,
req: Request<B>
) -> Response<BoxBody>where
S: ClientStreamingService<T::Decode, Response = T::Encode>,
B: Body + Send + 'static,
B::Error: Into<Box<dyn Error + Send + Sync>> + Send + 'static,
Handle a client side streaming gRPC request.
sourcepub async fn streaming<S, B>(
&mut self,
service: S,
req: Request<B>
) -> Response<BoxBody>where
S: StreamingService<T::Decode, Response = T::Encode> + Send,
S::ResponseStream: Send + 'static,
B: Body + Send + 'static,
B::Error: Into<Box<dyn Error + Send + Sync>> + Send,
pub async fn streaming<S, B>(
&mut self,
service: S,
req: Request<B>
) -> Response<BoxBody>where
S: StreamingService<T::Decode, Response = T::Encode> + Send,
S::ResponseStream: Send + 'static,
B: Body + Send + 'static,
B::Error: Into<Box<dyn Error + Send + Sync>> + Send,
Handle a bi-directional streaming gRPC request.