Struct thruster::Request

source ·
pub struct Request {
    pub headers: SmallVec<[((usize, usize), (usize, usize)); 8]>,
    pub params: Option<HashMap<String, String>>,
    /* private fields */
}
Expand description

The request object is the default request object provied by Thruster. If a different server is used, such as Hyper, then you’ll need to reference that server’s “request” documentation instead.

Fields§

§headers: SmallVec<[((usize, usize), (usize, usize)); 8]>§params: Option<HashMap<String, String>>

Implementations§

source§

impl Request

source

pub fn new() -> Self

Create a new, blank, request.

source

pub fn raw_body(&self) -> &[u8]

Get the raw pointer to the byte array of the request

source

pub fn body(&self) -> &str

Get the body as a utf8 encoded string

source

pub fn method(&self) -> &str

Get the method as a string

source

pub fn path(&self) -> &str

Get the path as a string (“/some/path”)

source

pub fn version(&self) -> u8

Get the HTTP version

source

pub fn headers(&self) -> HashMap<String, Vec<String>>

Get an HashMap of the provided headers. The HashMap is lazily computed, so avoid this method unless you need to access headers.

source

pub fn body_as<'a, T>(&self, body: &'a str) -> Result<T>where T: Deserialize<'a>,

Automatically apply a serde deserialization to the body

source

pub fn body_json<T>(&self) -> Result<T>where T: DeserializeOwned,

Reading body as json with given Deserialize struct

source

pub fn params(&self) -> &Option<HashMap<String, String>>

Fetch the params from the route, e.g. The route “/some/:key” when applied to an incoming request for “/some/value” will populate params with { key: "value" }

Trait Implementations§

source§

impl Debug for Request

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Request

source§

fn default() -> Request

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

impl ThrusterRequest for Request

source§

fn method(&self) -> &str

source§

fn path(&self) -> 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, 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.