Client

Struct Client 

Source
pub struct Client(/* private fields */);
Expand description

WebTransport wRPC client

Methods from Deref<Target = Connection>§

Source

pub async fn accept_uni(&self) -> Result<RecvStream, ConnectionError>

Asynchronously accepts a unidirectional stream.

This method is used to accept incoming unidirectional streams that have been initiated by the remote peer. It waits for the next unidirectional stream to be available, then wraps it in a RecvStream that can be used to read data from the stream.

§Cancel safety

This method is cancel safe.

Source

pub async fn accept_bi( &self, ) -> Result<(SendStream, RecvStream), ConnectionError>

Asynchronously accepts a bidirectional stream.

This method is used to accept incoming bidirectional streams that have been initiated by the remote peer. It waits for the next bidirectional stream to be available, then wraps it in a tuple containing a SendStream for sending data and a RecvStream for receiving data on the stream.

§Cancel safety

This method is cancel safe.

Source

pub async fn open_uni(&self) -> Result<OpeningUniStream, ConnectionError>

Asynchronously opens a new unidirectional stream.

This method is used to initiate the opening of a new unidirectional stream.

§Asynchronous Behavior

This method is asynchronous and involves two await points:

  1. The first await occurs during the initial phase of opening the stream, which may involve awaiting the flow controller. This wait is necessary to ensure proper resource allocation and flow control. It is safe to cancel this await point if needed.

  2. The second await is internal to the returned OpeningUniStream object when it is used to initialize the WebTransport stream. Cancelling this latter future before it completes may result in the stream being closed during initialization.

§Example
let send_stream = connection.open_uni().await?.await?;
Source

pub async fn open_bi(&self) -> Result<OpeningBiStream, ConnectionError>

Asynchronously opens a new bidirectional stream.

This method is used to initiate the opening of a new bidirectional stream.

§Asynchronous Behavior

This method is asynchronous and involves two await points:

  1. The first await occurs during the initial phase of opening the stream, which may involve awaiting the flow controller. This wait is necessary to ensure proper resource allocation and flow control. It is safe to cancel this await point if needed.

  2. The second await is internal to the returned OpeningBiStream object when it is used to initialize the WebTransport stream. Cancelling this latter future before it completes may result in the stream being closed during initialization.

§Example
let (send_stream, recv_stream) = connection.open_bi().await?.await?;
Source

pub async fn receive_datagram(&self) -> Result<Datagram, ConnectionError>

Asynchronously receives an application datagram from the remote peer.

This method is used to receive an application datagram sent by the remote peer over the connection. It waits for a datagram to become available and returns the received Datagram.

§Example
let datagram = connection.receive_datagram().await?;
Source

pub fn send_datagram<D>(&self, payload: D) -> Result<(), SendDatagramError>
where D: AsRef<[u8]>,

Sends an application datagram to the remote peer.

This method is used to send an application datagram to the remote peer over the connection. The datagram payload is provided as a reference to a slice of bytes.

§Example
connection.send_datagram(b"Hello, wtransport!")?;
Source

pub fn close(&self, error_code: VarInt, reason: &[u8])

Closes the connection immediately.

Source

pub async fn closed(&self) -> ConnectionError

Waits for the connection to be closed for any reason.

Source

pub fn session_id(&self) -> SessionId

Returns the WebTransport session identifier.

Source

pub fn remote_address(&self) -> SocketAddr

Returns the peer’s UDP address.

Note: as QUIC supports migration, remote address may change during connection. Furthermore, when IPv6 support is enabled, IPv4 addresses may be mapped to IPv6.

Source

pub fn stable_id(&self) -> usize

A stable identifier for this connection.

Peer addresses and connection IDs can change, but this value will remain fixed for the lifetime of the connection.

Source

pub fn max_datagram_size(&self) -> Option<usize>

Computes the maximum size of datagrams that may be passed to send_datagram.

Returns None if datagrams are unsupported by the peer or disabled locally.

This may change over the lifetime of a connection according to variation in the path MTU estimate. The peer can also enforce an arbitrarily small fixed limit, but if the peer’s limit is large this is guaranteed to be a little over a kilobyte at minimum.

Not necessarily the maximum size of received datagrams.

Source

pub fn rtt(&self) -> Duration

Current best estimate of this connection’s latency (round-trip-time).

Source

pub fn export_keying_material( &self, output: &mut [u8], label: &[u8], context: &[u8], ) -> Result<(), ExportKeyingMaterialError>

Derive keying material from this connection’s TLS session secrets.

When both peers call this method with the same label and context arguments and output buffers of equal length, they will get the same sequence of bytes in output. These bytes are cryptographically strong and pseudorandom, and are suitable for use as keying material.

See RFC5705 for more information.

Source

pub fn peer_identity(&self) -> Option<CertificateChain>

Returns the peer’s identity as a certificate chain if available.

This function returns an Option containing a CertificateChain. If the peer’s identity is available, it is converted into a CertificateChain and returned. If the peer’s identity is not available, None is returned.

Source

pub fn handshake_data(&self) -> HandshakeData

Retrieves handshake data associated with the connection.

Source

pub fn quic_connection(&self) -> &Connection

Returns a reference to the inner QUIC connection.

Source

pub fn quic_connection_mut(&mut self) -> &mut Connection

Returns a mutable reference to the inner QUIC connection.

Trait Implementations§

Source§

impl Accept for &Client

Source§

type Context = ()

Transport-specific invocation context
Source§

type Outgoing = SendStream

Outgoing byte stream
Source§

type Incoming = RecvStream

Incoming byte stream
Source§

async fn accept( &self, ) -> Result<(Self::Context, Self::Outgoing, Self::Incoming)>

Accept a connection returning a pair of streams and connection context
Source§

impl Accept for Client

Source§

type Context = ()

Transport-specific invocation context
Source§

type Outgoing = SendStream

Outgoing byte stream
Source§

type Incoming = RecvStream

Incoming byte stream
Source§

async fn accept( &self, ) -> Result<(Self::Context, Self::Outgoing, Self::Incoming)>

Accept a connection returning a pair of streams and connection context
Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Client

Source§

type Target = Connection

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Client

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl From<Connection> for Client

Source§

fn from(session: Connection) -> Self

Converts to this type from the input type.
Source§

impl Invoke for &Client

Source§

type Context = ()

Transport-specific invocation context
Source§

type Outgoing = Outgoing

Outgoing multiplexed byte stream
Source§

type Incoming = Incoming

Incoming multiplexed byte stream
Source§

async fn invoke<P>( &self, __arg1: Self::Context, instance: &str, func: &str, params: Bytes, paths: impl AsRef<[P]> + Send, ) -> Result<(Self::Outgoing, Self::Incoming)>
where P: AsRef<[Option<usize>]> + Send + Sync,

Invoke function func on instance instance Read more
Source§

impl Invoke for Client

Source§

type Context = ()

Transport-specific invocation context
Source§

type Outgoing = Outgoing

Outgoing multiplexed byte stream
Source§

type Incoming = Incoming

Incoming multiplexed byte stream
Source§

async fn invoke<P>( &self, __arg1: Self::Context, instance: &str, func: &str, params: Bytes, paths: impl AsRef<[P]> + Send, ) -> Result<(Self::Outgoing, Self::Incoming)>
where P: AsRef<[Option<usize>]> + Send + Sync,

Invoke function func on instance instance Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> AcceptExt for T
where T: Accept,

Source§

fn map_context<T, F>(self, f: F) -> AcceptMapContext<Self, F>
where F: Fn(Self::Context) -> T,

Maps Self::Context to a type T using F
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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> InvokeExt for T
where T: Invoke,

Source§

fn invoke_values<P, Params, Results>( &self, cx: Self::Context, instance: &str, func: &str, params: Params, paths: impl AsRef<[P]> + Send, ) -> impl Future<Output = Result<(Results, Option<impl Future<Output = Result<(), Error>> + Send + 'static>), Error>> + Send
where P: AsRef<[Option<usize>]> + Send + Sync, Params: TupleEncode<Self::Outgoing> + Send, Results: TupleDecode<Self::Incoming> + Send, <<Params as Encode<Self::Outgoing>>::Encoder as Encoder<Params>>::Error: Error + Send + Sync + 'static, <<Results as Decode<Self::Incoming>>::Decoder as Decoder>::Error: Error + Send + Sync + 'static,

Invoke function func on instance instance using typed Params and Results
Source§

fn invoke_values_blocking<P, Params, Results>( &self, cx: Self::Context, instance: &str, func: &str, params: Params, paths: impl AsRef<[P]> + Send, ) -> impl Future<Output = Result<Results, Error>> + Send
where P: AsRef<[Option<usize>]> + Send + Sync, Params: TupleEncode<Self::Outgoing> + Send, Results: TupleDecode<Self::Incoming> + Send, <<Params as Encode<Self::Outgoing>>::Encoder as Encoder<Params>>::Error: Error + Send + Sync + 'static, <<Results as Decode<Self::Incoming>>::Decoder as Decoder>::Error: Error + Send + Sync + 'static,

Invoke function func on instance instance using typed Params and Results This is like Self::invoke_values, but it only results once all I/O is done
Source§

fn timeout(&self, timeout: Duration) -> Timeout<'_, Self>

Returns a Timeout, wrapping Self with an implementation of Invoke, which will error, if call to Invoke::invoke does not return within a supplied timeout
Source§

fn timeout_owned(self, timeout: Duration) -> TimeoutOwned<Self>
where Self: Sized,

This is like InvokeExt::timeout, but moves Self and returns corresponding TimeoutOwned
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more