Request

Struct Request 

Source
pub struct Request<State = ()> { /* private fields */ }

Implementations§

Source§

impl<State> Request<State>

Source

pub fn method(&self) -> &Method

Returns a reference to the request’s method.

Source

pub fn uri(&self) -> &Uri

Returns a reference to the request’s URI.

Source

pub fn version(&self) -> Version

Returns the HTTP version that was used to make the request.

Source

pub fn headers(&self) -> &HeaderMap

Returns a reference to the request’s headers.

Source

pub fn extensions(&self) -> &Extensions

Returns a reference to the associated extensions.

Source

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

Returns a mutable reference to the associated extensions.

Source

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))
}
Source

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))
}
Source

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.

Source

pub fn cookies(&self) -> &CookieJar

Returns reference to the cookies associated with the request.

Source

pub fn state(&self) -> &Arc<State>

Returns a reference to an Arc that contains the state argument that was passed as an argument to the App constructor.

Source

pub fn map<U, F>(self, map: F) -> Self
where F: FnOnce(RequestBody) -> U, U: Body<Data = Bytes, Error = BoxError> + Send + Sync + 'static,

Consumes the request returning a new request with body mapped to the return type of the provided closure.

Source

pub fn into_parts(self) -> (RequestHead<State>, RequestBody)

Consumes the request and returns a tuple containing the head and body.

Source

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§

Source§

impl<State: Debug> Debug for Request<State>

Source§

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

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

impl<State> Pipe for Request<State>

Auto Trait Implementations§

§

impl<State = ()> !Freeze for Request<State>

§

impl<State = ()> !RefUnwindSafe for Request<State>

§

impl<State> Send for Request<State>
where State: Sync + Send,

§

impl<State> Sync for Request<State>
where State: Sync + Send,

§

impl<State> Unpin for Request<State>

§

impl<State = ()> !UnwindSafe for Request<State>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.