Struct madsim_tonic::client::Grpc
source · [−]pub struct Grpc<T> { /* private fields */ }
Expand description
A gRPC client dispatcher.
This will wrap some inner GrpcService
and will encode/decode
messages via the provided codec.
Each request method takes a Request
, a PathAndQuery
, and a
Codec
. The request contains the message to send via the
Codec::encoder
. The path determines the fully qualified path
that will be append to the outgoing uri. The path must follow
the conventions explained in the gRPC protocol definition under Path →
. An
example of this path could look like /greeter.Greeter/SayHello
.
Implementations
sourceimpl<T> Grpc<T>
impl<T> Grpc<T>
sourcepub fn new(inner: T) -> Grpc<T>
pub fn new(inner: T) -> Grpc<T>
Creates a new gRPC client with the provided GrpcService
.
sourcepub fn with_origin(inner: T, origin: Uri) -> Grpc<T>
pub fn with_origin(inner: T, origin: Uri) -> Grpc<T>
Creates a new gRPC client with the provided GrpcService
and Uri
.
The provided Uri will use only the scheme and authority parts as the path_and_query portion will be set for each method.
sourcepub fn send_compressed(self, encoding: CompressionEncoding) -> Grpc<T>
pub fn send_compressed(self, encoding: CompressionEncoding) -> Grpc<T>
Compress requests with the provided encoding.
Requires the server to accept the specified encoding, otherwise it might return an error.
Example
The most common way of using this is through a client generated by tonic-build:
use tonic::transport::Channel;
let channel = Channel::builder("127.0.0.1:3000".parse().unwrap())
.connect()
.await
.unwrap();
let client = TestClient::new(channel).send_compressed(CompressionEncoding::Gzip);
sourcepub fn accept_compressed(self, encoding: CompressionEncoding) -> Grpc<T>
pub fn accept_compressed(self, encoding: CompressionEncoding) -> Grpc<T>
Enable accepting compressed responses.
Requires the server to also support sending compressed responses.
Example
The most common way of using this is through a client generated by tonic-build:
use tonic::transport::Channel;
let channel = Channel::builder("127.0.0.1:3000".parse().unwrap())
.connect()
.await
.unwrap();
let client = TestClient::new(channel).accept_compressed(CompressionEncoding::Gzip);
sourcepub async fn ready(
&mut self
) -> Result<(), <T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::Error> where
T: GrpcService<UnsyncBoxBody<Bytes, Status>>,
pub async fn ready(
&mut self
) -> Result<(), <T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::Error> where
T: GrpcService<UnsyncBoxBody<Bytes, Status>>,
Check if the inner GrpcService
is able to accept a new request.
This will call GrpcService::poll_ready
until it returns ready or
an error. If this returns ready the inner GrpcService
is ready to
accept one more request.
sourcepub async fn unary<M1, M2, C>(
&mut self,
request: Request<M1>,
path: PathAndQuery,
codec: C
) -> Result<Response<M2>, Status> where
T: GrpcService<UnsyncBoxBody<Bytes, Status>>,
C: Codec<Encode = M1, Decode = M2>,
M1: 'static + Send + Sync,
M2: 'static + Send + Sync,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: 'static,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Body,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Send,
<<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
pub async fn unary<M1, M2, C>(
&mut self,
request: Request<M1>,
path: PathAndQuery,
codec: C
) -> Result<Response<M2>, Status> where
T: GrpcService<UnsyncBoxBody<Bytes, Status>>,
C: Codec<Encode = M1, Decode = M2>,
M1: 'static + Send + Sync,
M2: 'static + Send + Sync,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: 'static,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Body,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Send,
<<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
Send a single unary gRPC request.
sourcepub async fn client_streaming<S, M1, M2, C>(
&mut self,
request: Request<S>,
path: PathAndQuery,
codec: C
) -> Result<Response<M2>, Status> where
T: GrpcService<UnsyncBoxBody<Bytes, Status>>,
S: 'static + Stream<Item = M1> + Send,
C: Codec<Encode = M1, Decode = M2>,
M1: 'static + Send + Sync,
M2: 'static + Send + Sync,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: 'static,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Body,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Send,
<<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
pub async fn client_streaming<S, M1, M2, C>(
&mut self,
request: Request<S>,
path: PathAndQuery,
codec: C
) -> Result<Response<M2>, Status> where
T: GrpcService<UnsyncBoxBody<Bytes, Status>>,
S: 'static + Stream<Item = M1> + Send,
C: Codec<Encode = M1, Decode = M2>,
M1: 'static + Send + Sync,
M2: 'static + Send + Sync,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: 'static,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Body,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Send,
<<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
Send a client side streaming gRPC request.
sourcepub async fn server_streaming<M1, M2, C>(
&mut self,
request: Request<M1>,
path: PathAndQuery,
codec: C
) -> Result<Response<Streaming<M2>>, Status> where
T: GrpcService<UnsyncBoxBody<Bytes, Status>>,
C: Codec<Encode = M1, Decode = M2>,
M1: 'static + Send + Sync,
M2: 'static + Send + Sync,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: 'static,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Body,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Send,
<<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
pub async fn server_streaming<M1, M2, C>(
&mut self,
request: Request<M1>,
path: PathAndQuery,
codec: C
) -> Result<Response<Streaming<M2>>, Status> where
T: GrpcService<UnsyncBoxBody<Bytes, Status>>,
C: Codec<Encode = M1, Decode = M2>,
M1: 'static + Send + Sync,
M2: 'static + Send + Sync,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: 'static,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Body,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Send,
<<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
Send a server side streaming gRPC request.
sourcepub async fn streaming<S, M1, M2, C>(
&mut self,
request: Request<S>,
path: PathAndQuery,
codec: C
) -> Result<Response<Streaming<M2>>, Status> where
T: GrpcService<UnsyncBoxBody<Bytes, Status>>,
S: 'static + Stream<Item = M1> + Send,
C: Codec<Encode = M1, Decode = M2>,
M1: 'static + Send + Sync,
M2: 'static + Send + Sync,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: 'static,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Body,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Send,
<<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
pub async fn streaming<S, M1, M2, C>(
&mut self,
request: Request<S>,
path: PathAndQuery,
codec: C
) -> Result<Response<Streaming<M2>>, Status> where
T: GrpcService<UnsyncBoxBody<Bytes, Status>>,
S: 'static + Stream<Item = M1> + Send,
C: Codec<Encode = M1, Decode = M2>,
M1: 'static + Send + Sync,
M2: 'static + Send + Sync,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: 'static,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Body,
<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody: Send,
<<T as GrpcService<UnsyncBoxBody<Bytes, Status>>>::ResponseBody as Body>::Error: Into<Box<dyn Error + Sync + Send + 'static, Global>>,
Send 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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
sourcefn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message T
in a tonic::Request
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
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;
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
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;
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more