Struct Response

Source
pub struct Response { /* private fields */ }

Implementations§

Source§

impl Response

Source

pub fn new(body: ResponseBody) -> Self

Source

pub fn new_with_status(body: ResponseBody, status: StatusCode) -> Self

Source

pub fn html(body: String) -> Self

Source

pub fn text(body: String) -> Self

Source

pub fn json<T: Serialize>(body: &T) -> Result<Response, Error>

Source

pub fn stream<T, E>(stream: T) -> Self
where T: Stream<Item = Result<Frame<Bytes>, E>> + Send + Unpin + 'static, Error: From<E>,

Create a response from a stream of Result<Frame<Bytes>, Error>.

Source

pub fn not_found() -> Self

Source

pub fn build() -> ResponseBuilder

Source

pub fn from_parts(parts: Parts, body: ResponseBody) -> Self

Source

pub fn into_parts(self) -> (Parts, ResponseBody)

Consumes the response and returns a tuple containing the component parts of the response and the response body.

Source

pub fn map<F, T>(self, map: F) -> Self
where F: FnOnce(AnyBody<ByteBuffer>) -> T, T: Body<Data = Bytes, Error = Error> + Send + Sync + 'static,

Consumes the response returning a new response with body mapped to the return type of the provided closure map.

Source

pub fn body(&self) -> &ResponseBody

Source

pub fn body_mut(&mut self) -> &mut ResponseBody

Source

pub fn cookies(&self) -> Option<&CookieJar>

Returns a reference to the response cookies.

Source

pub fn cookies_mut(&mut self) -> &mut CookieJar

Returns a mutable reference to the response cookies.

Source

pub fn headers(&self) -> &HeaderMap

Source

pub fn headers_mut(&mut self) -> &mut HeaderMap

Source

pub fn set_header(&mut self, name: HeaderName, value: HeaderValue)

A shorthand method for self.headers_mut().insert(name, value).

Source

pub fn status(&self) -> StatusCode

Source

pub fn status_mut(&mut self) -> &mut StatusCode

Source

pub fn set_status(&mut self, status: StatusCode)

A shorthand method for *self.status_mut() = status.

Source

pub fn version(&self) -> Version

Trait Implementations§

Source§

impl Debug for Response

Source§

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

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

impl Default for Response

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Response<ResponseBody>> for Response

Source§

fn from(response: Response<ResponseBody>) -> Self

Converts to this type from the input type.
Source§

impl From<Response> for Response<AnyBody<ByteBuffer>>

Source§

fn from(from: Response) -> Self

Converts to this type from the input type.
Source§

impl IntoResponse for Response

Auto Trait Implementations§

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