#[repr(transparent)]pub struct ClientIp<F: Filter> {
pub inner: Option<IpAddr>,
/* private fields */
}Expand description
ClientIp extractor
Provided F parameter can be used to customize filter selection. Use nil type to only extract rightmost IP.
Defaults to axum::extract::ConnectInfo if corresponding header cannot provide ip
§Usage
use std::net::{IpAddr, Ipv4Addr};
use http_ip::axum08::{
routing::get,
handler::Handler,
Router,
};
use http_ip::axum08::ClientIp;
#[derive(Clone)]
struct MyState {
local_ip: IpAddr,
}
impl http_ip::axum08::extract::FromRef<MyState> for IpAddr {
#[inline(always)]
fn from_ref(state: &MyState) -> Self {
state.local_ip
}
}
async fn create_user(client_ip: ClientIp<IpAddr>) {
// Do whatever you want with client_ip now
}
let state = MyState {
local_ip: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))
};
let app: Router<MyState> = Router::new().route("/users", get(create_user)).with_state(state);Fields§
§inner: Option<IpAddr>Underlying IP addr if available
Implementations§
Trait Implementations§
Source§impl<S: Send + Sync, F: Send + Sync + Filter + Clone + FromRef<S>> FromRequestParts<S> for ClientIp<F>
impl<S: Send + Sync, F: Send + Sync + Filter + Clone + FromRef<S>> FromRequestParts<S> for ClientIp<F>
impl<F: Copy + Filter> Copy for ClientIp<F>
Auto Trait Implementations§
impl<F> Freeze for ClientIp<F>
impl<F> RefUnwindSafe for ClientIp<F>where
F: RefUnwindSafe,
impl<F> Send for ClientIp<F>where
F: Send,
impl<F> Sync for ClientIp<F>where
F: Sync,
impl<F> Unpin for ClientIp<F>where
F: Unpin,
impl<F> UnwindSafe for ClientIp<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request