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§
source§impl 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 body_string(&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§
source§impl Clone for BasicContext
impl Clone for BasicContext
source§impl Context for BasicContext
impl Context for BasicContext
type Response = Response
source§fn 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.
source§fn 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.
source§fn 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.
source§fn route(&self) -> &str
fn route(&self) -> &str
route is used to return the route from the incoming request as a string.
source§impl Default for BasicContext
impl Default for BasicContext
source§fn default() -> BasicContext
fn default() -> BasicContext
Returns the “default value” for a type. Read more
source§impl HasCookies for BasicContext
impl HasCookies for BasicContext
source§impl HasQueryParams for BasicContext
impl HasQueryParams for BasicContext
Auto Trait Implementations§
impl Freeze for BasicContext
impl RefUnwindSafe for BasicContext
impl Send for BasicContext
impl Sync for BasicContext
impl Unpin for BasicContext
impl UnwindSafe for BasicContext
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)