Skip to main content

Client

Struct Client 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn state(&self) -> ConnectivityState

The channel’s connectivity state.

Source

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.

Source

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.

Source

pub async fn unary( &self, path: &str, request: Vec<u8>, options: CallOptions, ) -> Result<UnaryResponse, Status>

Unary: one message out, one message back.

Source

pub async fn client_streaming<S>( &self, path: &str, requests: S, options: CallOptions, ) -> Result<UnaryResponse, Status>
where S: Stream<Item = Vec<u8>> + 'static,

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.

Source

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.

Source

pub async fn bidi_streaming<S>( &self, path: &str, requests: S, options: CallOptions, ) -> Result<Streaming, Status>
where S: Stream<Item = Vec<u8>> + 'static,

Bidirectional streaming: a stream out, a stream back, concurrently.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl TypedClient for Client

Source§

async fn unary_typed<Req, Res>( &self, path: &str, request: Req, options: CallOptions, ) -> Result<TypedResponse<Res>, Status>
where Req: Message, Res: Message + Default,

Unary with prost encode/decode.
Source§

async fn client_streaming_typed<Req, Res, S>( &self, path: &str, requests: S, options: CallOptions, ) -> Result<TypedResponse<Res>, Status>
where Req: Message + 'static, Res: Message + Default, S: Stream<Item = Req> + 'static,

Client streaming with prost encode/decode.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.