diff --git a/actix-limitation/src/lib.rs b/actix-limitation/src/lib.rs index 58a3fa5b3..de5e5b7d2 100644 --- a/actix-limitation/src/lib.rs +++ b/actix-limitation/src/lib.rs @@ -232,15 +232,11 @@ mod tests { let app = actix_web::test::init_service( actix_web::App::new() - .wrap(RateLimiter { - scope: Some("default"), - }) + .wrap(RateLimiter::scoped("default")) .app_data(limiters.clone()) .service( web::scope("/scoped") - .wrap(RateLimiter { - scope: Some("scoped"), - }) + .wrap(RateLimiter::scoped("scoped")) .service(index), ) .service(index), diff --git a/actix-limitation/src/middleware.rs b/actix-limitation/src/middleware.rs index c2fdc71c3..c968204d0 100644 --- a/actix-limitation/src/middleware.rs +++ b/actix-limitation/src/middleware.rs @@ -22,6 +22,13 @@ pub struct RateLimiter { pub scope: Option<&'static str>, } +impl RateLimiter { + /// Construct the rate limiter with a scope + pub fn scoped(scope: &'static str) -> Self { + RateLimiter { scope: Some(scope) } + } +} + impl Transform for RateLimiter where S: Service, Error = Error> + 'static,