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 fn max_decoding_message_size(self, limit: usize) -> Self
pub fn max_decoding_message_size(self, limit: usize) -> Self
Limits the maximum size of a decoded message.
§Example
The most common way of using this is through a server generated by tonic-build:
#[tonic::async_trait]
impl Example for Svc {
// ...
}
// Set the limit to 2MB, Defaults to 4MB.
let limit = 2 * 1024 * 1024;
let service = ExampleServer::new(Svc).max_decoding_message_size(limit);
sourcepub fn max_encoding_message_size(self, limit: usize) -> Self
pub fn max_encoding_message_size(self, limit: usize) -> Self
Limits the maximum size of a encoded message.
§Example
The most common way of using this is through a server generated by tonic-build:
#[tonic::async_trait]
impl Example for Svc {
// ...
}
// Set the limit to 2MB, Defaults to 4MB.
let limit = 2 * 1024 * 1024;
let service = ExampleServer::new(Svc).max_encoding_message_size(limit);
sourcepub async fn unary<S, B>(
&mut self,
service: S,
req: Request<B>,
) -> Response<BoxBody>
pub async fn unary<S, B>( &mut self, service: S, req: Request<B>, ) -> Response<BoxBody>
Handle a single unary gRPC request.
sourcepub async fn server_streaming<S, B>(
&mut self,
service: S,
req: Request<B>,
) -> Response<BoxBody>
pub async fn server_streaming<S, B>( &mut self, service: S, req: Request<B>, ) -> Response<BoxBody>
Handle a server side streaming request.
sourcepub async fn client_streaming<S, B>(
&mut self,
service: S,
req: Request<B>,
) -> Response<BoxBody>
pub async fn client_streaming<S, B>( &mut self, service: S, req: Request<B>, ) -> Response<BoxBody>
Handle a client side streaming gRPC request.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Grpc<T>where
T: Freeze,
impl<T> RefUnwindSafe for Grpc<T>where
T: RefUnwindSafe,
impl<T> Send for Grpc<T>where
T: Send,
impl<T> Sync for Grpc<T>where
T: Sync,
impl<T> Unpin for Grpc<T>where
T: Unpin,
impl<T> UnwindSafe for Grpc<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request