Struct silent::Request

source ·
pub struct Request { /* private fields */ }
Expand description

请求体

use silent::Request;
let req = Request::empty();

Implementations§

source§

impl Request

source

pub fn empty() -> Self

创建空请求体

source

pub fn remote(&self) -> SocketAddr

获取访问真实地址

source

pub fn req_mut(&mut self) -> &mut BaseRequest<ReqBody>

获取可变原请求体

source

pub fn path_params(&self) -> &HashMap<String, PathParam>

获取路径参数集合

source

pub fn get_path_params<'a, T>(&'a self, key: &'a str) -> Result<T, SilentError>
where T: TryFrom<&'a PathParam, Error = SilentError>,

获取路径参数

source

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

获取query参数

source

pub fn params_parse<T>(&mut self) -> Result<T, SilentError>
where for<'de> T: Deserialize<'de>,

转换query参数

source

pub fn replace_body(&mut self, body: ReqBody) -> ReqBody

获取请求body

source

pub fn take_body(&mut self) -> ReqBody

获取请求body

source

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

获取请求content_type

source

pub async fn form_data(&mut self) -> Result<&FormData, SilentError>

获取请求form_data

source

pub async fn body_parse<T>(&mut self, key: &str) -> Option<T>
where for<'de> T: Deserialize<'de>,

转换body参数

source

pub async fn files<'a>(&'a mut self, key: &'a str) -> Option<&'a Vec<FilePart>>

获取上传的文件

source

pub async fn json_parse<T>(&mut self) -> Result<T, SilentError>
where for<'de> T: Deserialize<'de>,

转换body参数按Json匹配

source

pub fn replace_extensions(&mut self, extensions: Extensions) -> Extensions

获取请求body

source

pub fn take_extensions(&mut self) -> Extensions

获取请求body

Methods from Deref<Target = BaseRequest<ReqBody>>§

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

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

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 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() -> Self

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

impl Deref for Request

§

type Target = Request<ReqBody>

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl DerefMut for Request

source§

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

Mutably dereferences the value.
source§

impl From<Request<ReqBody>> for Request

source§

fn from(req: BaseRequest<ReqBody>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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 T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more