pub struct Client { /* private fields */ }Expand description
A grpc-webnext client: a gRPC channel, not a handle to a socket.
Cheap to clone — clones share one tunnel, which is the point, since calls
multiplex over it. When that tunnel dies the channel redials on the next call,
the way tonic::transport::Channel does: the call that discovers the failure
reports it, and the one after reconnects. Watch Client::state_changes if the
application wants to say something about it.
Implementations§
Source§impl Client
impl Client
Sourcepub fn from_connection(
conn: H2Connection,
authority: impl Into<String>,
) -> Client
pub fn from_connection( conn: H2Connection, authority: impl Into<String>, ) -> Client
Build a client over an existing h2ts connection. Single-shot: there is no
way to redial, so a dropped tunnel stays dropped. Prefer
connect, which reconnects.
Sourcepub fn with_connector(
connector: Connector,
authority: impl Into<String>,
) -> Client
pub fn with_connector( connector: Connector, authority: impl Into<String>, ) -> Client
Build a reconnecting client from something that can open a tunnel on
demand. Each call to connector must yield a fresh connection, with its
driver already spawned.
Sourcepub fn over_transport(
transport: Transport,
authority: impl Into<String>,
options: ConnectOptions,
) -> (Client, impl Future<Output = ()>)
pub fn over_transport( transport: Transport, authority: impl Into<String>, options: ConnectOptions, ) -> (Client, impl Future<Output = ()>)
Build a client over any byte transport, returning the driver future the
caller must poll. Spawn it: wasm_bindgen_futures::spawn_local in a
browser, tokio::task::spawn_local on a LocalSet natively.
Single-shot, since the transport is consumed — see
from_connection.
Sourcepub fn state(&self) -> ConnectivityState
pub fn state(&self) -> ConnectivityState
The channel’s connectivity state.
Sourcepub fn state_changes(&self) -> impl Stream<Item = ConnectivityState> + 'static
pub fn state_changes(&self) -> impl Stream<Item = ConnectivityState> + 'static
Watch connectivity transitions — gRPC’s WaitForStateChange, as a stream.
Repeats are collapsed, so every item is a real change.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
True if there is no usable tunnel right now. A reconnecting client will open one on the next call; a single-shot one will not.
Sourcepub async fn unary(
&self,
path: &str,
request: Vec<u8>,
options: CallOptions,
) -> Result<UnaryResponse, Status>
pub async fn unary( &self, path: &str, request: Vec<u8>, options: CallOptions, ) -> Result<UnaryResponse, Status>
Unary: one message out, one message back.
Sourcepub async fn client_streaming<S>(
&self,
path: &str,
requests: S,
options: CallOptions,
) -> Result<UnaryResponse, Status>
pub async fn client_streaming<S>( &self, path: &str, requests: S, options: CallOptions, ) -> Result<UnaryResponse, Status>
Client streaming: a stream of messages out, one message back.
The request body is uploaded as the stream yields, under HTTP/2 flow control — a slow server pushes back rather than the messages piling up here.
Sourcepub async fn server_streaming(
&self,
path: &str,
request: Vec<u8>,
options: CallOptions,
) -> Result<Streaming, Status>
pub async fn server_streaming( &self, path: &str, request: Vec<u8>, options: CallOptions, ) -> Result<Streaming, Status>
Server streaming: one message out, a stream of messages back.
Sourcepub async fn bidi_streaming<S>(
&self,
path: &str,
requests: S,
options: CallOptions,
) -> Result<Streaming, Status>
pub async fn bidi_streaming<S>( &self, path: &str, requests: S, options: CallOptions, ) -> Result<Streaming, Status>
Bidirectional streaming: a stream out, a stream back, concurrently.
Source§impl Client
impl Client
Sourcepub fn into_tonic(self) -> TonicService
pub fn into_tonic(self) -> TonicService
Wrap this channel as a tonic transport, for generated client stubs.
Trait Implementations§
Source§impl TypedClient for Client
impl TypedClient for Client
Source§async fn unary_typed<Req, Res>(
&self,
path: &str,
request: Req,
options: CallOptions,
) -> Result<TypedResponse<Res>, Status>
async fn unary_typed<Req, Res>( &self, path: &str, request: Req, options: CallOptions, ) -> Result<TypedResponse<Res>, Status>
Source§async fn client_streaming_typed<Req, Res, S>(
&self,
path: &str,
requests: S,
options: CallOptions,
) -> Result<TypedResponse<Res>, Status>
async fn client_streaming_typed<Req, Res, S>( &self, path: &str, requests: S, options: CallOptions, ) -> Result<TypedResponse<Res>, Status>
Auto Trait Implementations§
impl !RefUnwindSafe for Client
impl !Send for Client
impl !Sync for Client
impl !UnwindSafe for Client
impl Freeze for Client
impl Unpin for Client
impl UnsafeUnpin for Client
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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