Struct thruster::context::basic_context::BasicContext
source · [−]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
params: Option<HashMap<String, String>>
query_params: Option<HashMap<String, String>>
request: Request
status: u32
headers: HashMap<String, String>
Implementations
sourceimpl BasicContext
impl BasicContext
pub fn new() -> BasicContext
sourcepub fn json<T: Serialize>(&mut self, body: T)
pub fn json<T: Serialize>(&mut self, body: T)
Set Generic Serialize as body and sets header Content-Type to application/json
sourcepub fn set_status(&mut self, code: u32) -> &mut BasicContext
pub fn set_status(&mut self, code: u32) -> &mut BasicContext
Set the response status code
pub fn get_body(&self) -> String
sourcepub fn content_type(&mut self, c_type: &str)
pub fn content_type(&mut self, c_type: &str)
Set the response Content-Type
. A shortcode for
ctx.set("Content-Type", "some-val");
sourcepub fn redirect(&mut self, destination: &str)
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);
Sets a cookie on the response
Trait Implementations
sourceimpl Clone for BasicContext
impl Clone for BasicContext
sourceimpl Context for BasicContext
impl Context for BasicContext
type Response = Response
sourcefn get_response(self) -> Self::Response
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. Read more
sourcefn set_body(&mut self, body: Vec<u8>)
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. Read more
sourcefn set_body_bytes(&mut self, body_bytes: Bytes)
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. Read more
sourcefn route(&self) -> &str
fn route(&self) -> &str
route is used to return the route from the incoming request as a string.
sourceimpl Default for BasicContext
impl Default for BasicContext
sourcefn default() -> BasicContext
fn default() -> BasicContext
Returns the “default value” for a type. Read more
sourceimpl HasCookies for BasicContext
impl HasCookies for BasicContext
fn get_header(&self, key: &str) -> Vec<String>
sourceimpl HasQueryParams for BasicContext
impl HasQueryParams for BasicContext
fn set_query_params(&mut self, query_params: HashMap<String, String>)
Auto Trait Implementations
impl RefUnwindSafe for BasicContext
impl Send for BasicContext
impl Sync for BasicContext
impl Unpin for BasicContext
impl UnwindSafe for BasicContext
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more