Skip to content

Commit

Permalink
add extractor for SocketAddr type. (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow authored Jan 16, 2024
1 parent a5672d8 commit c106c61
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions web/src/handler/impls.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::net::SocketAddr;

use crate::{
body::ResponseBody,
context::WebContext,
Expand Down Expand Up @@ -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<C>;

#[inline]
async fn from_request(ctx: &'a WebContext<'r, C, B>) -> Result<Self, Self::Error> {
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<C>;

#[inline]
async fn from_request(ctx: &'a WebContext<'r, C, B>) -> Result<Self, Self::Error> {
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<C>;
Expand Down

0 comments on commit c106c61

Please sign in to comment.