pub struct RequestContext {
    pub request: Request<Body<'static>>,
    pub params: Params,
    pub reader: UriReader,
    /* private fields */
}
Expand description

Wrapper for http::Request containing params and cursor.

Fields§

§request: Request<Body<'static>>

The http::Request instance.

§params: Params

Params collected from the router.

§reader: UriReader

The uri reader.

Implementations§

source§

impl RequestContext

source

pub fn new(request: Request<Body<'static>>, stream: TcpStream) -> Self

Creates a new instance of request context.

source

pub fn next_handler(self) -> Response

Call the next handler, returning the response.

Panics

This function might panic if no next handler exists.

source

pub fn set_next_handler(&mut self, next: fn(_: RequestContext) -> Response)

Set the next handler.

This is used internally by the router! macro.

Methods from Deref<Target = Request<Body<'static>>>§

source

pub fn method(&self) -> &Method

Returns a reference to the associated HTTP method.

Examples
let request: Request<()> = Request::default();
assert_eq!(*request.method(), Method::GET);
source

pub fn method_mut(&mut self) -> &mut Method

Returns a mutable reference to the associated HTTP method.

Examples
let mut request: Request<()> = Request::default();
*request.method_mut() = Method::PUT;
assert_eq!(*request.method(), Method::PUT);
source

pub fn uri(&self) -> &Uri

Returns a reference to the associated URI.

Examples
let request: Request<()> = Request::default();
assert_eq!(*request.uri(), *"/");
source

pub fn uri_mut(&mut self) -> &mut Uri

Returns a mutable reference to the associated URI.

Examples
let mut request: Request<()> = Request::default();
*request.uri_mut() = "/hello".parse().unwrap();
assert_eq!(*request.uri(), *"/hello");
source

pub fn version(&self) -> Version

Returns the associated version.

Examples
let request: Request<()> = Request::default();
assert_eq!(request.version(), Version::HTTP_11);
source

pub fn version_mut(&mut self) -> &mut Version

Returns a mutable reference to the associated version.

Examples
let mut request: Request<()> = Request::default();
*request.version_mut() = Version::HTTP_2;
assert_eq!(request.version(), Version::HTTP_2);
source

pub fn headers(&self) -> &HeaderMap<HeaderValue>

Returns a reference to the associated header field map.

Examples
let request: Request<()> = Request::default();
assert!(request.headers().is_empty());
source

pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>

Returns a mutable reference to the associated header field map.

Examples
let mut request: Request<()> = Request::default();
request.headers_mut().insert(HOST, HeaderValue::from_static("world"));
assert!(!request.headers().is_empty());
source

pub fn extensions(&self) -> &Extensions

Returns a reference to the associated extensions.

Examples
let request: Request<()> = Request::default();
assert!(request.extensions().get::<i32>().is_none());
source

pub fn extensions_mut(&mut self) -> &mut Extensions

Returns a mutable reference to the associated extensions.

Examples
let mut request: Request<()> = Request::default();
request.extensions_mut().insert("hello");
assert_eq!(request.extensions().get(), Some(&"hello"));
source

pub fn body(&self) -> &T

Returns a reference to the associated HTTP body.

Examples
let request: Request<String> = Request::default();
assert!(request.body().is_empty());
source

pub fn body_mut(&mut self) -> &mut T

Returns a mutable reference to the associated HTTP body.

Examples
let mut request: Request<String> = Request::default();
request.body_mut().push_str("hello world");
assert!(!request.body().is_empty());

Trait Implementations§

source§

impl<'a> AsRef<Request<Body<'a>>> for RequestContext

source§

fn as_ref(&self) -> &Request<Body<'a>>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Deref for RequestContext

§

type Target = Request<Body<'static>>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for RequestContext

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl FromOwnedRequest for RequestContext

§

type Rejection = Infallible

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
source§

fn from_owned_request(req: RequestContext) -> Result<Self, Self::Rejection>

Extract from an owned instance of the request. The first extractor in handlers will use this method, and can help avoid cloning in many cases.

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> Same<T> for T

§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V