Crate rocket_governor[][src]

Expand description

rocket-governor - rate-limiting implementation for Rocket web framework

Provides rocket guards implementing rate-limiting (based on governor).

It is used with the derive macro rocket_governor_derive.

Example

use rocket::{catchers, get, http::Status, launch, routes};
use rocket_governor::{Method, Quota, RocketGovernable};
use rocket_governor_derive::RocketGovernor;

#[derive(RocketGovernor)]
pub struct RateLimitGuard;

impl<'r> RocketGovernable<'r> for RateLimitGuard {
    fn quota(_method: Method, _route_name: &str) -> Quota {
        Quota::per_second(Self::nonzero(1u32))
    }
}

#[get("/")]
fn route_example(_limitguard: RateLimitGuard) -> Status {
    Status::Ok
}

#[launch]
fn launch_rocket() -> _ {
    rocket::build()
        .mount("/", routes![route_example])
        .register("/", catchers![ratelimitguard_rocket_governor_catcher])
}

See rocket_governor Github project for more information.

Modules

Structs

An integer that is known not to equal zero.

A rate-limiting quota.

Enums

Errors in govern (rate limit).

Representation of HTTP methods.

Traits

The RocketGovernable guard trait.