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
sourceimpl<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>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.
Trait Implementations
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourcefn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>impl<T> Future for Instrumented<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
where
S: Into<Dispatch>,
T: Future, type Output = <T as Future>::Output;
sourcefn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
fn with_current_subscriber(self) -> WithDispatch<Self>ⓘNotable traits for WithDispatch<T>impl<T> Future for WithDispatch<T>where
T: Future, type Output = <T as Future>::Output;
T: Future, type Output = <T as Future>::Output;