Struct warp_ratelimit::DistinctVisitor[][src]

pub struct DistinctVisitor {
    pub first_request_time: Instant,
    pub num_requests: u64,
    pub ip: IpAddr,
}

A single distinct visitor for the filter to keep track of.

Example

use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::{Arc, Mutex};
use std::time::Duration;

#[tokio::main]
async fn main() {
    // Memory for filter
    let mem = Arc::new(Mutex::new(Vec::new()));
    // Ratelimiting filter that lets in 10 requests from each user every 6 minutes
    let filter = warp_ratelimit::ratelimit_filter(Arc::clone(&mem), 10, Duration::new(360, 0)).await;
    warp::test::request()
        .remote_addr(SocketAddr::new(IpAddr::V4(Ipv4Addr::new(1, 1, 1, 1)), 8080))
        .reply(&filter)
        .await;
    // Memory should contain single visitor
    let mem_lock = mem.lock().unwrap();
    assert_eq!((*mem_lock).len(), 1);
    let first_elem = (*mem_lock)[0].clone();
    assert_eq!(first_elem.ip, Ipv4Addr::new(1, 1, 1, 1));
    assert_eq!(first_elem.num_requests, 1);
}

Fields

first_request_time: Instantnum_requests: u64ip: IpAddr

Trait Implementations

impl Clone for DistinctVisitor[src]

impl Debug for DistinctVisitor[src]

impl Eq for DistinctVisitor[src]

impl PartialEq<DistinctVisitor> for DistinctVisitor[src]

impl StructuralEq for DistinctVisitor[src]

impl StructuralPartialEq for DistinctVisitor[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,