[go: up one dir, main page]

Response

Struct Response 

Source
pub struct Response<T, F = JsonFormat> { /* private fields */ }
Expand description

A typed fully-buffered HTTP response.

The type parameter T is a marker type that indicates what the caller should expect to be able to deserialize the body into. Service client methods should return a Response<SomeModel> where SomeModel is the service-specific response type. For example, a service client method that returns a list of secrets should return Response<ListSecretsResponse>.

The type parameter F is a marker type that indicates the format of the data, defaulting to JSON. XML is supported, and NoFormat indicates a binary body or no body expected e.g., for HTTP 204.

Given a Response<T, F>, a user can deserialize the body formatted as type F into the intended body type T by calling Response::into_model; however, because the type T is just a marker type, you can also access the raw ResponseBody using Response::into_body.

Implementations§

Source§

impl<T, F> Response<T, F>

Source

pub fn status(&self) -> StatusCode

Get the status code from the response.

Source

pub fn headers(&self) -> &Headers

Get the headers from the response.

Source

pub fn body(&self) -> &ResponseBody

Get the ResponseBody.

Source

pub fn deconstruct(self) -> (StatusCode, Headers, ResponseBody)

Deconstruct the HTTP response into its components.

Source

pub fn into_body(self) -> ResponseBody

Get the ResponseBody.

Source

pub fn to_raw_response(&self) -> RawResponse

Create a RawResponse by cloning borrowed data.

Source§

impl<T, F> Response<T, F>
where T: DeserializeWith<F>, F: Format,

Source

pub fn into_model(self) -> Result<T, Error>

Fetches the entire body and tries to convert it into type T.

This is the preferred method for parsing the body of a service response into it’s default model type.

§Examples

let secret_client = create_secret_client();
let response = secret_client.get_secret().await;
assert_eq!(response.status(), StatusCode::Ok);
let model = response.into_model().unwrap();
assert_eq!(model.name, "database_password");
assert_eq!(model.value, "hunter2");

Trait Implementations§

Source§

impl<T, F> Debug for Response<T, F>

Source§

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

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

impl<T, F> From<RawResponse> for Response<T, F>

Source§

fn from(raw: RawResponse) -> Response<T, F>

Converts to this type from the input type.
Source§

impl<T, F> From<Response<T, F>> for RawResponse

Source§

fn from(response: Response<T, F>) -> RawResponse

Converts to this type from the input type.
Source§

impl<P, F> Page for Response<P, F>
where P: DeserializeWith<F> + Page + Send, F: Format + Send,

Source§

type Item = <P as Page>::Item

The type of items in the collection.
Source§

type IntoIter = <P as Page>::IntoIter

The type containing items in the collection e.g., Vec<Self::Item>.
Source§

fn into_items<'async_trait>( self, ) -> Pin<Box<dyn Future<Output = Result<Self::IntoIter>> + Send + 'async_trait>>
where Self: 'async_trait,

Gets a single page of items returned by a collection request to a service.

Auto Trait Implementations§

§

impl<T, F = JsonFormat> !Freeze for Response<T, F>

§

impl<T, F> RefUnwindSafe for Response<T, F>

§

impl<T, F> Send for Response<T, F>
where T: Send, F: Send,

§

impl<T, F> Sync for Response<T, F>
where T: Sync, F: Sync,

§

impl<T, F> Unpin for Response<T, F>
where T: Unpin, F: Unpin,

§

impl<T, F> UnwindSafe for Response<T, F>
where T: UnwindSafe, F: 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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
Source§

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