pub struct WebContext<'a, C = (), B = RequestBody> { /* private fields */ }
Expand description
web context type focus on stateful and side effect based request data access.
Implementations§
Source§impl<'a, C, B> WebContext<'a, C, B>
impl<'a, C, B> WebContext<'a, C, B>
Sourcepub fn reborrow(&mut self) -> WebContext<'_, C, B>
pub fn reborrow(&mut self) -> WebContext<'_, C, B>
Reborrow Self so the ownership of WebRequest is not lost.
§Note:
Reborrow is not pure and receiver of it can mutate Self in any way they like.
§Example:
// a function need ownership of request but not return it in output.
fn handler(req: WebContext<'_>) -> Result<(), ()> {
Err(())
}
// use reborrow to avoid pass request by value.
match handler(req.reborrow()) {
// still able to access request after handler return.
Ok(_) => assert_eq!(req.state(), &()),
Err(_) => assert_eq!(req.state(), &())
}
Sourcepub async fn extract<'r, T>(&'r self) -> Result<T, T::Error>where
T: FromRequest<'r, Self>,
pub async fn extract<'r, T>(&'r self) -> Result<T, T::Error>where
T: FromRequest<'r, Self>,
extract typed data from WebContext. type must impl FromRequest trait. this is a shortcut method that avoiding explicit import of mentioned trait.
§Examples
async fn extract(ctx: WebContext<'_, usize>) {
// extract state from context.
let StateRef(state1) = ctx.extract().await.unwrap();
// equivalent of above method with explicit trait import.
use xitca_web::handler::FromRequest;
let StateRef(state2) = StateRef::<'_, usize>::from_request(&ctx).await.unwrap();
// two extractors will return the same type and data state.
assert_eq!(state1, state2);
}
Sourcepub fn req(&self) -> &WebRequest<()>
pub fn req(&self) -> &WebRequest<()>
Get an immutable reference of WebRequest
Sourcepub fn req_mut(&mut self) -> &mut WebRequest<()>
pub fn req_mut(&mut self) -> &mut WebRequest<()>
Get a mutable reference of WebRequest
Sourcepub fn body(&self) -> Ref<'_, B>
pub fn body(&self) -> Ref<'_, B>
Get a immutable reference of RequestBody
Sourcepub fn body_borrow_mut(&self) -> RefMut<'_, B>
pub fn body_borrow_mut(&self) -> RefMut<'_, B>
Get a mutable reference of RequestBody
Sourcepub fn body_get_mut(&mut self) -> &mut B
pub fn body_get_mut(&mut self) -> &mut B
Get a mutable reference of RequestBody This API takes &mut WebRequest so it bypass runtime borrow checker and therefore has zero runtime overhead.
pub fn take_request(&mut self) -> WebRequest<B>where
B: Default,
Sourcepub fn into_response<ResB: Into<ResponseBody>>(self, body: ResB) -> WebResponse
pub fn into_response<ResB: Into<ResponseBody>>(self, body: ResB) -> WebResponse
Transform self to a WebResponse with given body type.
The heap allocation of request would be re-used.
Sourcepub fn as_response<ResB: Into<ResponseBody>>(
&mut self,
body: ResB,
) -> WebResponse
pub fn as_response<ResB: Into<ResponseBody>>( &mut self, body: ResB, ) -> WebResponse
Transform &mut self to a WebResponse with given body type.
The heap allocation of request would be re-used.
Trait Implementations§
Source§impl<C, B, T> BorrowReq<T> for WebContext<'_, C, B>
impl<C, B, T> BorrowReq<T> for WebContext<'_, C, B>
Source§impl<C, B, T> BorrowReqMut<T> for WebContext<'_, C, B>
impl<C, B, T> BorrowReqMut<T> for WebContext<'_, C, B>
fn borrow_mut(&mut self) -> &mut T
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a HeaderMap
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a HeaderMap
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a Method
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a Method
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a WebRequest<()>
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a WebRequest<()>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a RequestExt<()>
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a RequestExt<()>
type Type<'b> = &'b RequestExt<()>
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a SocketAddr
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a SocketAddr
type Type<'b> = &'b SocketAddr
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a Uri
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a Uri
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a WebContext<'a, C, B>where
C: 'static,
B: 'static,
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a WebContext<'a, C, B>where
C: 'static,
B: 'static,
type Type<'b> = &'b WebContext<'b, C, B>
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for ()
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for ()
Source§impl<'a, 'r, C, B, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for (Bytes, Limit<LIMIT>)where
B: BodyStream + Default,
impl<'a, 'r, C, B, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for (Bytes, Limit<LIMIT>)where
B: BodyStream + Default,
Source§impl<'a, 'r, C, B, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for (BytesMut, Limit<LIMIT>)where
B: BodyStream + Default,
impl<'a, 'r, C, B, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for (BytesMut, Limit<LIMIT>)where
B: BodyStream + Default,
Source§impl<'a, 'r, C, B, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for (Vec<u8>, Limit<LIMIT>)where
B: BodyStream + Default,
impl<'a, 'r, C, B, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for (Vec<u8>, Limit<LIMIT>)where
B: BodyStream + Default,
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Body<B>where
B: BodyStream + Default,
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Body<B>where
B: BodyStream + Default,
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Byteswhere
B: BodyStream + Default,
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Byteswhere
B: BodyStream + Default,
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for BytesMutwhere
B: BodyStream + Default,
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for BytesMutwhere
B: BodyStream + Default,
Source§impl<'a, 'r, C, B, K> FromRequest<'a, WebContext<'r, C, B>> for CookieJar<K>
impl<'a, 'r, C, B, K> FromRequest<'a, WebContext<'r, C, B>> for CookieJar<K>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for ExtensionKey
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for ExtensionKey
type Type<'b> = ExtensionKey
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for ExtensionOwn<T>
impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for ExtensionOwn<T>
type Type<'b> = ExtensionOwn<T>
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for ExtensionRef<'a, T>
impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for ExtensionRef<'a, T>
type Type<'b> = ExtensionRef<'b, T>
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for ExtensionsRef<'a>
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for ExtensionsRef<'a>
type Type<'b> = ExtensionsRef<'b>
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, C, B, T, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for Form<T, LIMIT>
impl<'a, 'r, C, B, T, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for Form<T, LIMIT>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for HeaderMap
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for HeaderMap
Source§impl<'a, 'r, C, B, const HEADER_NAME: usize> FromRequest<'a, WebContext<'r, C, B>> for HeaderRef<'a, HEADER_NAME>
impl<'a, 'r, C, B, const HEADER_NAME: usize> FromRequest<'a, WebContext<'r, C, B>> for HeaderRef<'a, HEADER_NAME>
Source§impl<'a, 'r, C, B, T, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for Json<T, LIMIT>
impl<'a, 'r, C, B, T, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for Json<T, LIMIT>
Source§impl<'a, 'r, C, B, T, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for LazyForm<T, LIMIT>
impl<'a, 'r, C, B, T, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for LazyForm<T, LIMIT>
Source§impl<'a, 'r, C, B, T, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for LazyJson<T, LIMIT>
impl<'a, 'r, C, B, T, const LIMIT: usize> FromRequest<'a, WebContext<'r, C, B>> for LazyJson<T, LIMIT>
Source§impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for LazyParams<'a, T>
impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for LazyParams<'a, T>
type Type<'b> = LazyParams<'b, T>
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for LazyQuery<'a, T>where
T: Deserialize<'static>,
impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for LazyQuery<'a, T>where
T: Deserialize<'static>,
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Method
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Method
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Multipart<B>where
B: BodyStream + Default,
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Multipart<B>where
B: BodyStream + Default,
Source§impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for Option<T>where
T: FromRequest<'a, WebContext<'r, C, B>>,
impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for Option<T>where
T: FromRequest<'a, WebContext<'r, C, B>>,
type Type<'b> = Option<<T as FromRequest<'a, WebContext<'r, C, B>>>::Type<'b>>
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, T, C, B> FromRequest<'a, WebContext<'r, C, B>> for Params<T>where
T: for<'de> Deserialize<'de>,
impl<'a, 'r, T, C, B> FromRequest<'a, WebContext<'r, C, B>> for Params<T>where
T: for<'de> Deserialize<'de>,
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for ParamsRef<'a>
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for ParamsRef<'a>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for PathOwn
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for PathOwn
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for PathRef<'a>
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for PathRef<'a>
Source§impl<'a, 'r, C, B, K> FromRequest<'a, WebContext<'r, C, B>> for Private<K>
impl<'a, 'r, C, B, K> FromRequest<'a, WebContext<'r, C, B>> for Private<K>
Source§impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for Query<T>where
T: for<'de> Deserialize<'de>,
impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for Query<T>where
T: for<'de> Deserialize<'de>,
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for WebRequest<()>
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for WebRequest<()>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for RequestExt<()>
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for RequestExt<()>
type Type<'b> = RequestExt<()>
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, C, B, T, E> FromRequest<'a, WebContext<'r, C, B>> for Result<T, E>where
T: FromRequest<'a, WebContext<'r, C, B>, Error = E>,
impl<'a, 'r, C, B, T, E> FromRequest<'a, WebContext<'r, C, B>> for Result<T, E>where
T: FromRequest<'a, WebContext<'r, C, B>, Error = E>,
type Type<'b> = Result<<T as FromRequest<'a, WebContext<'r, C, B>>>::Type<'b>, <T as FromRequest<'a, WebContext<'r, C, B>>>::Error>
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, C, B, K> FromRequest<'a, WebContext<'r, C, B>> for Signed<K>
impl<'a, 'r, C, B, K> FromRequest<'a, WebContext<'r, C, B>> for Signed<K>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for SocketAddr
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for SocketAddr
type Type<'b> = SocketAddr
type Error = Error
async fn from_request( ctx: &'a WebContext<'r, C, B>, ) -> Result<Self, Self::Error>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for StateKeywhere
C: Borrow<Self>,
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for StateKeywhere
C: Borrow<Self>,
Source§impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for StateOwn<T>where
C: BorrowState<T>,
T: Clone,
impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for StateOwn<T>where
C: BorrowState<T>,
T: Clone,
Source§impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for StateRef<'a, T>where
C: BorrowState<T>,
T: ?Sized + 'static,
impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for StateRef<'a, T>where
C: BorrowState<T>,
T: ?Sized + 'static,
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Stringwhere
B: BodyStream + Default,
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Stringwhere
B: BodyStream + Default,
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Uri
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Uri
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for UriOwn
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for UriOwn
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for UriRef<'a>
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for UriRef<'a>
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Vec<u8>where
B: BodyStream + Default,
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for Vec<u8>where
B: BodyStream + Default,
Source§impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for WebSocket<B>where
C: 'static,
B: BodyStream + Default + 'static,
impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for WebSocket<B>where
C: 'static,
B: BodyStream + Default + 'static,
Source§impl<C, B, I, Res, Err> IntoObject<I, ()> for WebContext<'_, C, B>
impl<C, B, I, Res, Err> IntoObject<I, ()> for WebContext<'_, C, B>
Source§type Object = RouteObject<(), Box<dyn for<'r> ServiceObject<WebContext<'r, C, B>, Error = Err, Response = Res>>, <I as Service>::Error>
type Object = RouteObject<(), Box<dyn for<'r> ServiceObject<WebContext<'r, C, B>, Error = Err, Response = Res>>, <I as Service>::Error>
I
.Source§fn into_object(inner: I) -> Self::Object
fn into_object(inner: I) -> Self::Object
Self::Object
from I
.