Skip to main content

UnaryConn

Struct UnaryConn 

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

A unary or client-streaming call: one request (or a stream of requests) in, exactly one response out.

Build it with the chainable with_* setters, then .await it — awaiting sends the request(s), reads the single response, drains the stream to its trailers, and enforces the one-response cardinality. Transport-level failures (connection, non-200 head) surface as the await’s Err; the RPC’s logical grpc-status is read afterward via status / into_message, so response metadata stays readable even on a logical error.

Implementations§

Source§

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

Source

pub fn unary<C>(client: &Client, path: &str, request: Req) -> Self
where C: Codec<Req> + Codec<Resp>,

A unary call sending the single request.

Source

pub fn client_streaming<C>( client: &Client, path: &str, requests: impl Stream<Item = Req> + Send + 'static, ) -> Self
where C: Codec<Req> + Codec<Resp>,

A client-streaming call sending each message from requests.

Source

pub fn with_ascii_metadata(self, key: &str, value: &str) -> Self

Attach an ASCII request-metadata entry. Chainable; takes effect when the call fires.

Source

pub fn with_binary_metadata(self, key: &str, value: impl Into<Vec<u8>>) -> Self

Attach a binary (-bin) request-metadata entry. Chainable.

Source

pub fn with_timeout(self, timeout: Duration) -> Self

Set this call’s deadline, timeout from now. Chainable.

Source

pub fn cancel_handle(&self) -> CancelHandle

A handle that cancels this call from elsewhere (including before/while it is awaited).

Source

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

The response’s initial metadata, once the call has run. None before.

Source

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

The response’s trailing metadata, once the call has run. None before.

Source

pub fn message(&self) -> Option<&Resp>

The response message, if the call ran and yielded one. None before the call, and on the error path.

Source

pub fn status(&self) -> Result<(), Status>

The RPC’s logical verdict, once the call has run: Ok(()) on success, the server’s grpc-status (or a cardinality violation) as Err. Ok(()) before the call has run.

Source

pub fn into_message(self) -> Result<Resp, Status>

Consume the conn and yield the response message, folding the logical verdict: Err on a grpc-status error (or cardinality violation), else the single message. Read metadata / trailers first if you need them on the error path.

Trait Implementations§

Source§

impl<Req, Resp> IntoFuture for UnaryConn<Req, Resp>
where Req: Send + 'static, Resp: Send + 'static,

Source§

type Output = Result<UnaryConn<Req, Resp>, Status>

The output that the future will produce on completion.
Source§

type IntoFuture = Pin<Box<dyn Future<Output = <UnaryConn<Req, Resp> as IntoFuture>::Output> + Send>>

Which kind of future are we turning this into?
Source§

fn into_future(self) -> Self::IntoFuture

Creates a future from a value. Read more

Auto Trait Implementations§

§

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

§

impl<Req, Resp> !Sync for UnaryConn<Req, Resp>

§

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

§

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

§

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

§

impl<Req, Resp> Freeze for UnaryConn<Req, Resp>
where Resp: Freeze,

§

impl<Req, Resp> Send for UnaryConn<Req, Resp>
where Resp: Send,

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.