[][src]Struct tide::ResponseBuilder

pub struct ResponseBuilder(_);

Response Builder

Provides an ergonomic way to chain the creation of a response. This is generally accessed through Response::builder

Example

let mut response = Response::builder(203)
    .body("body")
    .content_type(mime::HTML)
    .header("custom-header", "value")
    .build();

assert_eq!(response.take_body().into_string().await.unwrap(), "body");
assert_eq!(response.status(), StatusCode::NonAuthoritativeInformation);
assert_eq!(response["custom-header"], "value");
assert_eq!(response.content_type(), Some(mime::HTML));

Implementations

impl ResponseBuilder[src]

pub fn build(self) -> Response[src]

Returns the inner Response

pub fn header(
    mut self: Self,
    key: impl Into<HeaderName>,
    value: impl ToHeaderValues
) -> Self
[src]

Sets a header on the response.

let response = Response::builder(200).header("header-name", "header-value").build();
assert_eq!(response["header-name"], "header-value");

pub fn content_type(mut self: Self, content_type: impl Into<Mime>) -> Self[src]

Sets the Content-Type header on the response.

let response = Response::builder(200).content_type(mime::HTML).build();
assert_eq!(response["content-type"], "text/html;charset=utf-8");

pub fn body(mut self: Self, body: impl Into<Body>) -> Self[src]

Sets the body of the response.

let mut response = Response::builder(200).body(json!({ "any": "Into<Body>"})).build();
assert_eq!(response.take_body().into_string().await.unwrap(), "{\"any\":\"Into<Body>\"}");

Trait Implementations

impl Debug for ResponseBuilder[src]

impl Into<Response> for ResponseBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,