Skip to main content

GrpcClientConn

Struct GrpcClientConn 

Source
pub struct GrpcClientConn<Req, Resp> { /* private fields */ }
Available on crate feature client only.
Expand description

An owned, typed gRPC client call.

Construct one through a generated <Service>Client method (or new), then drive it with send / close_send / recv. Initial and trailing response metadata are available via headers / trailers once they’ve arrived — on the error path too.

Implementations§

Source§

impl<Req, Resp> GrpcClientConn<Req, Resp>
where Req: Send + 'static, Resp: Send + 'static,

Source

pub fn new<C>( client: &Client, path: &str, metadata: Metadata, timeout: Option<Duration>, full_duplex: bool, ) -> Self
where C: Codec<Req> + Codec<Resp>,

Open a call over codec C, deriving the content-type and encode/decode from the Codec impl and the outbound compression from the client’s configured grpc-encoding. No network I/O happens until close_send or the first recv.

Source

pub fn cancel_handle(&self) -> CancelHandle

A cancellation handle for this call. Clone it freely; calling cancel on any clone cancels this RPC.

Source

pub fn headers(&self) -> Option<&Headers>

The response’s initial metadata, available once the head has arrived (after the first recv, or after close_send for half-duplex). None before then.

Source

pub fn trailers(&self) -> Option<&Headers>

The response’s trailing metadata, available once the response stream has ended. None before end-of-stream.

Source

pub async fn send(&mut self, message: Req) -> Result<(), Status>

Frame and send one request message.

Before the request has fired (the common case for half-duplex), this accumulates the frame into the request body. Once a full-duplex call is live, it writes the frame on the wire immediately.

Source

pub async fn close_send(&mut self) -> Result<(), Status>

Half-close the request side (sends END_STREAM).

For send-then-receive shapes this is what fires the request: the accumulated body is sent with END_STREAM and the response head is awaited. For a live full-duplex call it closes the write half, leaving the read side open.

Source

pub async fn recv(&mut self) -> Result<Option<Resp>, Status>

Read the next response message: Ok(Some) for a message, Ok(None) at a clean end-of-stream (grpc-status: 0), Err for an RPC error (which also ends the stream). Trailing metadata is available via trailers afterward.

Auto Trait Implementations§

§

impl<Req, Resp> !RefUnwindSafe for GrpcClientConn<Req, Resp>

§

impl<Req, Resp> !Unpin for GrpcClientConn<Req, Resp>

§

impl<Req, Resp> !UnsafeUnpin for GrpcClientConn<Req, Resp>

§

impl<Req, Resp> !UnwindSafe for GrpcClientConn<Req, Resp>

§

impl<Req, Resp> Freeze for GrpcClientConn<Req, Resp>

§

impl<Req, Resp> Send for GrpcClientConn<Req, Resp>

§

impl<Req, Resp> Sync for GrpcClientConn<Req, Resp>

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Server for T
where T: 'static,

Source§

async fn unary<Req, Resp>( conn: Conn, f: impl AsyncFnOnce(&mut GrpcServerConn<Self>, Req) -> Result<Resp, Status>, ) -> Conn
where Self: Codec<Req> + Codec<Resp>, Req: Send + 'static, Resp: Send + 'static,

Available on crate feature server only.
Unary RPC: read exactly one request, await the user function, emit one response frame followed by grpc-status trailers.
Source§

async fn client_streaming<Resp>( conn: Conn, f: impl AsyncFnOnce(&mut GrpcServerConn<Self>) -> Result<Resp, Status>, ) -> Conn
where Self: Codec<Resp>, Resp: Send + 'static,

Available on crate feature server only.
Client-streaming RPC: hand the user a GrpcServerConn from which they read the request stream (conn.requests::<Req>()); emit the single response frame and grpc-status trailers.
Source§

async fn server_streaming<Req, Resp, S>( conn: Conn, f: impl AsyncFnOnce(&mut GrpcServerConn<Self>, Req) -> Result<S, Status>, ) -> Conn
where Self: Codec<Req> + Codec<Resp>, Req: Send + 'static, Resp: Send + 'static, S: Stream<Item = Result<Resp, Status>> + Send + 'static,

Available on crate feature server only.
Server-streaming RPC: read one request, await the user function for a response Stream, then frame each item lazily into the response body with grpc-status trailers derived from how the stream ended.
Source§

async fn bidi<Req, Resp, R>( conn: Conn, prologue: impl AsyncFnOnce(&mut GrpcServerConn<Self>) -> Result<R, Status>, ) -> Conn
where Self: Codec<Req> + Codec<Resp>, Req: Send + 'static, Resp: Send + 'static, R: BidiResponder<Req, Resp>,

Available on crate feature server only.
Bidirectional-streaming RPC — the run-phase prologue. Hand the user a GrpcServerConn from which they may read early request messages (to decide response headers) and set initial metadata, then return a BidiResponder that drives the read-while-write loop after the head is flushed. Returning Err(Status) rejects before the flush (trailers-only, no upgrade). See crate::server::bidi for the seam mechanics.
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.