Skip to main content

IHttpResponse

Trait IHttpResponse 

Source
pub trait IHttpResponse: Send {
    // Required methods
    fn status(&self) -> u16;
    fn set_status(&mut self, code: u16);
    fn set_header(&mut self, key: &str, value: &str);
    fn write_bytes<'life0, 'async_trait>(
        &'life0 mut self,
        data: Vec<u8>,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn has_body(&self) -> bool { ... }
    fn write_text<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        text: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

HTTP response abstraction.

Analogous to ASP.NET Core’s HttpResponse.

Methods are non-generic to maintain dyn-compatibility.

Required Methods§

Source

fn status(&self) -> u16

Get the current HTTP status code.

Source

fn set_status(&mut self, code: u16)

Source

fn set_header(&mut self, key: &str, value: &str)

Source

fn write_bytes<'life0, 'async_trait>( &'life0 mut self, data: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Write raw bytes as the response body.

Provided Methods§

Source

fn has_body(&self) -> bool

Whether a response body has been written.

Source

fn write_text<'life0, 'life1, 'async_trait>( &'life0 mut self, text: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Write a UTF-8 string as the response body.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§