Trait viz::RequestExt

source ·
pub trait RequestExt: Sealed + Sized {
Show 25 methods // Required methods fn schema(&self) -> Option<&Scheme>; fn path(&self) -> &str; fn query_string(&self) -> Option<&str>; fn query<T>(&self) -> Result<T, PayloadError> where T: DeserializeOwned; fn header<K, T>(&self, key: K) -> Option<T> where K: AsHeaderName, T: FromStr; fn header_typed<H>(&self) -> Option<H> where H: Header; fn content_length(&self) -> Option<u64>; fn content_type(&self) -> Option<Mime>; fn extract<T>( &mut self ) -> impl Future<Output = Result<T, <T as FromRequest>::Error>> + Send where T: FromRequest; fn incoming(&mut self) -> Result<Body, PayloadError>; fn bytes( &mut self ) -> impl Future<Output = Result<Bytes, PayloadError>> + Send; fn text( &mut self ) -> impl Future<Output = Result<String, PayloadError>> + Send; fn form<T>( &mut self ) -> impl Future<Output = Result<T, PayloadError>> + Send where T: DeserializeOwned; fn json<T>( &mut self ) -> impl Future<Output = Result<T, PayloadError>> + Send where T: DeserializeOwned; fn multipart( &mut self ) -> impl Future<Output = Result<FormData<Body>, PayloadError>> + Send; fn state<T>(&self) -> Option<T> where T: Clone + Send + Sync + 'static; fn set_state<T>(&mut self, t: T) -> Option<T> where T: Clone + Send + Sync + 'static; fn cookies(&self) -> Result<Cookies, CookiesError>; fn cookie<S>(&self, name: S) -> Option<Cookie<'_>> where S: AsRef<str>; fn session(&self) -> &Session; fn params<T>(&self) -> Result<T, ParamsError> where T: DeserializeOwned; fn param<T>(&self, name: &str) -> Result<T, ParamsError> where T: FromStr, <T as FromStr>::Err: Display; fn route_info(&self) -> &Arc<RouteInfo>; fn remote_addr(&self) -> Option<&SocketAddr>; fn realip(&self) -> Option<RealIp>;
}
Expand description

The Request Extension.

Required Methods§

source

fn schema(&self) -> Option<&Scheme>

Get URL’s schema of this request.

source

fn path(&self) -> &str

Get URL’s path of this request.

source

fn query_string(&self) -> Option<&str>

Get URL’s query string of this request.

source

fn query<T>(&self) -> Result<T, PayloadError>

Available on crate feature query only.

Get query data by type.

§Errors

Will return PayloadError::UrlDecode if decoding the query string fails.

source

fn header<K, T>(&self, key: K) -> Option<T>
where K: AsHeaderName, T: FromStr,

Get a header with the key.

source

fn header_typed<H>(&self) -> Option<H>
where H: Header,

Get a header with the specified type.

source

fn content_length(&self) -> Option<u64>

Get the size of this request’s body.

source

fn content_type(&self) -> Option<Mime>

Get the media type of this request.

source

fn extract<T>( &mut self ) -> impl Future<Output = Result<T, <T as FromRequest>::Error>> + Send
where T: FromRequest,

Extract the data from this request by the specified type.

source

fn incoming(&mut self) -> Result<Body, PayloadError>

Get an incoming body.

§Errors

Will return PayloadError::Empty or PayloadError::Used if the incoming does not exist or be used.

source

fn bytes(&mut self) -> impl Future<Output = Result<Bytes, PayloadError>> + Send

Return with a Bytes representation of the request body.

source

fn text(&mut self) -> impl Future<Output = Result<String, PayloadError>> + Send

Return with a Text representation of the request body.

source

fn form<T>(&mut self) -> impl Future<Output = Result<T, PayloadError>> + Send

Available on crate feature form only.

Return with a application/x-www-form-urlencoded FormData by the specified type representation of the request body.

source

fn json<T>(&mut self) -> impl Future<Output = Result<T, PayloadError>> + Send

Available on crate feature json only.

Return with a JSON by the specified type representation of the request body.

source

fn multipart( &mut self ) -> impl Future<Output = Result<FormData<Body>, PayloadError>> + Send

Available on crate feature multipart only.

Return with a multipart/form-data FormData by the specified type representation of the request body.

source

fn state<T>(&self) -> Option<T>
where T: Clone + Send + Sync + 'static,

Available on crate feature state only.

Return a shared state by the specified type.

source

fn set_state<T>(&mut self, t: T) -> Option<T>
where T: Clone + Send + Sync + 'static,

Available on crate feature state only.

Store a shared state.

source

fn cookies(&self) -> Result<Cookies, CookiesError>

Available on crate feature cookie only.

Get a wrapper of cookie-jar for managing cookies.

§Errors

Will return CookiesError if getting cookies fails.

source

fn cookie<S>(&self, name: S) -> Option<Cookie<'_>>
where S: AsRef<str>,

Available on crate feature cookie only.

Get a cookie by the specified name.

source

fn session(&self) -> &Session

Available on crate feature session only.

Get current session.

source

fn params<T>(&self) -> Result<T, ParamsError>

Available on crate feature params only.

Get all parameters.

§Errors

Will return ParamsError if deserializer the parameters fails.

source

fn param<T>(&self, name: &str) -> Result<T, ParamsError>
where T: FromStr, <T as FromStr>::Err: Display,

Available on crate feature params only.

Get single parameter by name.

§Errors

Will return ParamsError if deserializer the single parameter fails.

source

fn route_info(&self) -> &Arc<RouteInfo>

Available on crate feature params only.

Get current route.

source

fn remote_addr(&self) -> Option<&SocketAddr>

Get remote addr.

source

fn realip(&self) -> Option<RealIp>

Get realip.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl RequestExt for Request<Body>

source§

fn schema(&self) -> Option<&Scheme>

source§

fn path(&self) -> &str

source§

fn query_string(&self) -> Option<&str>

source§

fn query<T>(&self) -> Result<T, PayloadError>

Available on crate feature query only.
source§

fn header<K, T>(&self, key: K) -> Option<T>
where K: AsHeaderName, T: FromStr,

source§

fn header_typed<H>(&self) -> Option<H>
where H: Header,

source§

fn content_length(&self) -> Option<u64>

source§

fn content_type(&self) -> Option<Mime>

source§

async fn extract<T>(&mut self) -> Result<T, <T as FromRequest>::Error>
where T: FromRequest,

source§

fn incoming(&mut self) -> Result<Body, PayloadError>

source§

async fn bytes(&mut self) -> Result<Bytes, PayloadError>

source§

async fn text(&mut self) -> Result<String, PayloadError>

source§

async fn form<T>(&mut self) -> Result<T, PayloadError>

Available on crate feature form only.
source§

async fn json<T>(&mut self) -> Result<T, PayloadError>

Available on crate feature json only.
source§

async fn multipart(&mut self) -> Result<FormData<Body>, PayloadError>

Available on crate feature multipart only.
source§

fn state<T>(&self) -> Option<T>
where T: Clone + Send + Sync + 'static,

Available on crate feature state only.
source§

fn set_state<T>(&mut self, t: T) -> Option<T>
where T: Clone + Send + Sync + 'static,

Available on crate feature state only.
source§

fn cookies(&self) -> Result<Cookies, CookiesError>

Available on crate feature cookie only.
source§

fn cookie<S>(&self, name: S) -> Option<Cookie<'_>>
where S: AsRef<str>,

Available on crate feature cookie only.
source§

fn session(&self) -> &Session

Available on crate feature session only.
source§

fn params<T>(&self) -> Result<T, ParamsError>

Available on crate feature params only.
source§

fn param<T>(&self, name: &str) -> Result<T, ParamsError>
where T: FromStr, <T as FromStr>::Err: Display,

Available on crate feature params only.
source§

fn remote_addr(&self) -> Option<&SocketAddr>

source§

fn route_info(&self) -> &Arc<RouteInfo>

Available on crate feature params only.
source§

fn realip(&self) -> Option<RealIp>

Implementors§