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>,
    /* private fields */
}

Fields§

§cookies: Vec<Cookie>§params: Option<HashMap<String, String>>§query_params: Option<HashMap<String, String>>§request: Request§status: u32§headers: HashMap<String, String>

Implementations§

source§

impl BasicContext

source

pub fn new() -> BasicContext

source

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

Set the body as a string

source

pub fn json<T: Serialize>(&mut self, body: T)

Set Generic Serialize as body and sets header Content-Type to application/json

source

pub fn set_status(&mut self, code: u32) -> &mut BasicContext

Set the response status code

source

pub fn body_string(&self) -> String

source

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

Set the response Content-Type. A shortcode for

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

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

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

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

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

Sets a cookie on the response

Trait Implementations§

source§

impl Clone for BasicContext

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Context for BasicContext

§

type Response = Response

source§

fn get_response(self) -> Self::Response

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.
source§

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

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.
source§

fn set_body_bytes(&mut self, body_bytes: Bytes)

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.
source§

fn route(&self) -> &str

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

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

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

fn remove(&mut self, key: &str)

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

fn status(&mut self, code: u16)

sets the status on the response.
source§

impl Default for BasicContext

source§

fn default() -> BasicContext

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

impl HasCookies for BasicContext

source§

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

source§

fn get_cookies(&self) -> Vec<String>

source§

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

source§

impl HasQueryParams for BasicContext

source§

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.