diff --git a/web/src/handler/impls.rs b/web/src/handler/impls.rs index 9b87bc9d..512b74c8 100644 --- a/web/src/handler/impls.rs +++ b/web/src/handler/impls.rs @@ -1,3 +1,5 @@ +use core::net::SocketAddr; + use crate::{ body::ResponseBody, context::WebContext, @@ -87,6 +89,26 @@ 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 &'a SocketAddr { + type Type<'b> = &'b SocketAddr; + type Error = Error; + + #[inline] + async fn from_request(ctx: &'a WebContext<'r, C, B>) -> Result { + Ok(ctx.req().body().socket_addr()) + } +} + +impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for SocketAddr { + type Type<'b> = SocketAddr; + type Error = Error; + + #[inline] + async fn from_request(ctx: &'a WebContext<'r, C, B>) -> Result { + Ok(*ctx.req().body().socket_addr()) + } +} + impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for &'a Method { type Type<'b> = &'b Method; type Error = Error;