http1::response

Struct Response

source
pub struct Response<T> { /* private fields */ }
Expand description

Represents an HTTP response.

This struct holds the HTTP status code, headers, and body of the response. The body type is generic, allowing different types of body content.

Implementations§

source§

impl<T> Response<T>

source

pub fn new(status: StatusCode, body: T) -> Self

Creates a new Response with the given status code and body.

§Parameters
  • status: The HTTP status code for the response.
  • body: The content of the response body.
§Returns

A Response with the provided status and body, and empty headers.

source

pub fn with_version(status: StatusCode, version: Version, body: T) -> Self

Creates a new Response with the given status code and body and version

source

pub fn status(&self) -> StatusCode

Returns the status code of the response.

source

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

Returns a mutable reference to the status code of the response.

source

pub fn version(&self) -> Version

Returns the http version of the response.

source

pub fn version_mut(&mut self) -> &mut Version

Returns a mutable reference of the http version of the response.

source

pub fn headers(&self) -> &Headers

Returns a reference to the response headers.

source

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

Returns a mutable reference to the response headers.

source

pub fn body(&self) -> &T

Returns a reference to the response body.

source

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

Returns a mutable reference to the response body.

source

pub fn extensions(&self) -> &Extensions

Returns a reference to the response body.

source

pub fn extensions_mut(&mut self) -> &mut Extensions

Returns a mutable reference to the response extensions.

source

pub fn map_body<F: FnOnce(T) -> R, R>(self, f: F) -> Response<R>

Maps this response body

source

pub fn into_parts(self) -> (StatusCode, Headers, T, Version)

Consumes the response and splits it into its components: the status code, headers, and body.

§Returns

A tuple containing the status code, headers, and body.

source

pub fn into_body(self) -> T

Returns a the body.

source§

impl Response<()>

source

pub fn builder() -> Builder

Returns a Builder to construct a new Response.

§Example
use http1::{status::StatusCode, response::Response};

let response = Response::builder()
    .status(StatusCode::OK)
    .body("Hello, World!");

Trait Implementations§

source§

impl<T: Debug> Debug for Response<T>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Response<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for Response<T>

§

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

§

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

§

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

§

impl<T> !UnwindSafe for Response<T>

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.