Struct thruster::context::basic_context::BasicContext[][src]

pub struct BasicContext {
    pub cookies: Vec<Cookie>,
    pub params: Option<HashMap<String, String>>,
    pub query_params: Option<HashMap<String, String>>,
    pub request: Request,
    pub status: u32,
    pub headers: HashMap<String, String>,
    // some fields omitted
}

Fields

cookies: Vec<Cookie>params: Option<HashMap<String, String>>query_params: Option<HashMap<String, String>>request: Requeststatus: u32headers: HashMap<String, String>

Implementations

impl BasicContext[src]

pub fn new() -> BasicContext[src]

pub fn body(&mut self, body_string: &str)[src]

Set the body as a string

pub fn get_body(&self) -> String[src]

pub fn status(&mut self, code: u32)[src]

Set the response status code

pub fn content_type(&mut self, c_type: &str)[src]

Set the response Content-Type. A shortcode for

ctx.set("Content-Type", "some-val");

pub fn redirect(&mut self, destination: &str)[src]

Set up a redirect, will default to 302, but can be changed after the fact.

ctx.set("Location", "/some-path");
ctx.status(302);

pub fn cookie(&mut self, name: &str, value: &str, options: &CookieOptions)[src]

Sets a cookie on the response

Trait Implementations

impl Clone for BasicContext[src]

fn clone(&self) -> Self[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Context for BasicContext[src]

type Response = Response

fn get_response(self) -> Self::Response[src]

get_response returns a fully created response object based on the contents of the Context. This means setting the body according to whatever has been stored via set_body and/or set_body_bytes, as well as adding the proper headers that have been added via the set method. Read more

fn set_body(&mut self, body: Vec<u8>)[src]

set_body is used to set the body using a vec of bytes on the context. The contents will be used later for generating the correct response. Read more

fn set_body_bytes(&mut self, body_bytes: Bytes)[src]

set_body_byte is used to set the body using a Bytes object on the context. The contents will be used later for generating the correct response. Read more

fn route(&self) -> &str[src]

route is used to return the route from the incoming request as a string.

fn set(&mut self, key: &str, value: &str)[src]

set is used to set a header on the outgoing response.

fn remove(&mut self, key: &str)[src]

remove is used to remove a header on the outgoing response.

impl Default for BasicContext[src]

fn default() -> BasicContext[src]

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

impl HasCookies for BasicContext[src]

fn set_cookies(&mut self, cookies: Vec<Cookie>)[src]

fn get_cookies(&self) -> Vec<String>[src]

fn get_header(&self, key: &str) -> Vec<String>[src]

impl HasQueryParams for BasicContext[src]

fn set_query_params(&mut self, query_params: HashMap<String, String>)[src]

Auto Trait Implementations

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.