Skip to main content

DirectResponse

Struct DirectResponse 

Source
pub struct DirectResponse { /* private fields */ }
Expand description

What a surface answered, stated without a transport.

Implementations§

Source§

impl DirectResponse

Source

pub fn new(status: HttpStatus) -> DirectResponse

Answers with a status and nothing else.

Source

pub fn content( status: HttpStatus, content_type: &str, body: impl Into<Vec<u8>>, ) -> DirectResponse

Answers with a status, a content type, and a body.

Source

pub fn with_header(self, name: &str, value: &str) -> DirectResponse

States one header on this answer.

Source

pub fn with_body(self, body: impl Into<Vec<u8>>) -> DirectResponse

States the body of this answer.

Source

pub fn with_chunks( self, chunks: Pin<Box<dyn Stream<Item = Result<Vec<u8>, Error>> + Send>>, ) -> DirectResponse

States a body this answer produces over time.

Source

pub fn into_body(self) -> DirectBody

Returns what this answer carries, which is either bytes or what produces them.

Source

pub async fn collected(self) -> DirectResponse

Answers the same thing with every chunk of its body taken.

A body already in hand is already collected. One produced over time is read to its end, which is what anything reading an answer whole has to do.

Source

pub fn with_status(self, status: HttpStatus) -> DirectResponse

Answers the same thing under a different status.

Source

pub fn status(&self) -> HttpStatus

Returns the status this answer carries.

Source

pub fn header(&self, name: &str) -> Option<&str>

Returns the value of one header, matched without regard to case.

Source

pub fn headers(&self) -> impl Iterator<Item = (&str, &str)>

Returns every header this answer carries, in the order it states them.

Source

pub fn body(&self) -> &[u8]

Returns the bytes this answer already carries, which a body still to come has none of.

Source

pub fn text(&self) -> String

Returns the body read as text, however it was encoded.

Trait Implementations§

Source§

impl Debug for DirectResponse

Source§

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

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

impl From<DirectError> for DirectResponse

Source§

fn from(error: DirectError) -> DirectResponse

Converts to this type from the input type.

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<This> HttpProgramExt<This> for This

Source§

fn compile_http<Program>( &self, program: Program, ) -> <Program as HttpProgramAlg<This>>::Route
where Program: HttpProgramAlg<This>,

Compiles a named HTTP program with this interpreter.

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.