pub struct Request<State = ()> { /* private fields */ }Implementations§
Source§impl<State> Request<State>
impl<State> Request<State>
Sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Returns a reference to the associated extensions.
Sourcepub fn extensions_mut(&mut self) -> &mut Extensions
pub fn extensions_mut(&mut self) -> &mut Extensions
Returns a mutable reference to the associated extensions.
Sourcepub fn param<'b>(&self, name: &'b str) -> PathParam<'_, 'b>
pub fn param<'b>(&self, name: &'b str) -> PathParam<'_, 'b>
Returns a convenient wrapper around an optional reference to the path
parameter in the request’s uri with the provided name.
§Example
use via::{Next, Request, Response};
async fn hello(request: Request, _: Next) -> via::Result {
let name = request.param("name").into_result()?;
Response::build().text(format!("Hello, {}!", name))
}Sourcepub fn query<'b>(&self, name: &'b str) -> QueryParam<'_, 'b> ⓘ
pub fn query<'b>(&self, name: &'b str) -> QueryParam<'_, 'b> ⓘ
Returns a convenient wrapper around an optional references to the query
parameters in the request’s uri with the provided name.
§Example
use via::{Next, Request, Response};
async fn hello(request: Request, _: Next) -> via::Result {
// Attempt to parse the first query parameter named `n` to a `usize`
// no greater than 1000. If the query parameter doesn't exist or
// can't be converted to a `usize`, default to 1.
let n = request.query("n").first().parse().unwrap_or(1).min(1000);
// Get a reference to the path parameter `name` from the request uri.
let name = request.param("name").into_result()?;
// Create a greeting message with the provided `name`.
let message = format!("Hello, {}!\n", name);
// Send a response with our greeting message, repeated `n` times.
Response::build().text(message.repeat(n))
}Sourcepub fn header<K>(&self, key: K) -> Result<Option<&str>, Error>where
K: AsHeaderName,
pub fn header<K>(&self, key: K) -> Result<Option<&str>, Error>where
K: AsHeaderName,
Returns a result that contains an Option<&str> with the header value associated with the provided key.
§Errors
Status Code: 400
If the header value associated with key contains a char that is not considered to be visible ascii.
Returns reference to the cookies associated with the request.
Sourcepub fn map<U, F>(self, map: F) -> Self
pub fn map<U, F>(self, map: F) -> Self
Consumes the request returning a new request with body mapped to the return type of the provided closure.
Sourcepub fn into_parts(self) -> (RequestHead<State>, RequestBody)
pub fn into_parts(self) -> (RequestHead<State>, RequestBody)
Consumes the request and returns a tuple containing the head and body.
Sourcepub async fn into_future(self) -> Result<DataAndTrailers, Error>
pub async fn into_future(self) -> Result<DataAndTrailers, Error>
Consumes the request and returns a future that resolves with the data in the body.
Trait Implementations§
Auto Trait Implementations§
impl<State = ()> !Freeze for Request<State>
impl<State = ()> !RefUnwindSafe for Request<State>
impl<State> Send for Request<State>
impl<State> Sync for Request<State>
impl<State> Unpin for Request<State>
impl<State = ()> !UnwindSafe for Request<State>
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more