Skip to main content

UnaryResponse

Struct UnaryResponse 

Source
pub struct UnaryResponse<Resp> { /* private fields */ }
Expand description

Response from a unary RPC call.

Contains the decoded response message along with response headers and trailing metadata.

Implementations§

Source§

impl<Resp> UnaryResponse<Resp>

Source

pub fn headers(&self) -> &HeaderMap

Returns the response headers.

Source

pub fn into_view(self) -> Resp

Consume the response, returning just the body.

For generated clients this is an OwnedView — zero-copy, move semantics, suitable for keeping the decoded body around without copying. Field access on it goes through reborrow(); for inline reads prefer view(), and for an owned struct use into_owned().

Source

pub fn trailers(&self) -> &HeaderMap

Returns the trailing metadata.

Source

pub fn into_parts(self) -> (HeaderMap, Resp, HeaderMap)

Consume the response, returning (headers, body, trailers).

Source§

impl<V> UnaryResponse<OwnedView<V>>
where V: MessageView<'static>,

Convenience for the common generated-client case where the body is an OwnedView. Generated unary client methods always return this shape.

Source

pub fn into_owned(self) -> V::Owned

Consume the response and return the fully-owned message, discarding headers and trailers.

This allocates and copies all borrowed fields (strings, bytes, nested messages). Prefer zero-copy view access via view() unless you need to pass the owned struct to code that expects it, or store it in a collection.

let owned: FooResponse = client.foo(req).await?.into_owned();

Infallible — see into_owned_parts() for the argument.

Source

pub fn into_owned_parts(self) -> (HeaderMap, V::Owned, HeaderMap)

Consume the response, returning (headers, owned message, trailers).

The metadata-preserving sibling of into_owned(), for callers that also need the response’s header and trailer metadata.

Infallible: OwnedView::to_owned_message cannot fail, because an OwnedView can only come from buffa’s wire decoder and conversion replays under the budget the decode already charged.

Source§

impl<V> UnaryResponse<OwnedView<V>>
where V: ViewReborrow,

Zero-copy read access for OwnedView bodies whose view supports reborrowing (every buffa-generated view does).

Source

pub fn view(&self) -> &V::Reborrowed<'_>

Borrow the response message view, tied to &self.

Field access on the returned view is zero-copy:

let resp = client.foo(req).await?;
assert_eq!(resp.view().name, "expected");  // &str, no allocation

See also into_view() to keep the decoded body and into_owned() for an owned struct.

Trait Implementations§

Source§

impl<Resp: Debug> Debug for UnaryResponse<Resp>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Resp> Freeze for UnaryResponse<Resp>
where Resp: Freeze,

§

impl<Resp> RefUnwindSafe for UnaryResponse<Resp>
where Resp: RefUnwindSafe,

§

impl<Resp> Send for UnaryResponse<Resp>
where Resp: Send,

§

impl<Resp> Sync for UnaryResponse<Resp>
where Resp: Sync,

§

impl<Resp> Unpin for UnaryResponse<Resp>
where Resp: Unpin,

§

impl<Resp> UnsafeUnpin for UnaryResponse<Resp>
where Resp: UnsafeUnpin,

§

impl<Resp> UnwindSafe for UnaryResponse<Resp>
where Resp: UnwindSafe,

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> 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, 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<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