A Tower service and layer that provides a rate-limiting backed by governor. Based heavily on the work done for actix-governor. Works with Axum, Hyper, Tower, Tonic, and anything else based on Tower!

# Features:

async fn hello() -> &'static str { "Hello world" }

[tokio::main]

async fn main() {

// Configure tracing if desired
// construct a subscriber that prints formatted traces to stdout
let subscriber = tracing_subscriber::FmtSubscriber::new();
// use that subscriber to process traces emitted after this point
tracing::subscriber::set_global_default(subscriber).unwrap();

// Allow bursts with up to five requests per IP address
// and replenishes one element every two seconds
let governor_conf = GovernorConfigBuilder::default()
    .per_second(2)
    .burst_size(5)
    .finish()
    .unwrap();
// build our application with a route
let app = Router::new()
    // `GET /` goes to `root`
    .route("/", get(hello))
    .layer(
        ServiceBuilder::new()
            // this middleware goes above `GovernorLayer` because it will receive
            // errors returned by `GovernorLayer`
            .layer(HandleErrorLayer::new(|e: BoxError| async move {
                // Provided Error handling function to turn Errors into Responses
                // Feel free to write your own!
                display_error(e)
            }))
            .layer(GovernorLayer {
                config: &governor_conf,
            })
    );


// run our app with hyper
// `axum::Server` is a re-export of `hyper::Server`
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
    .serve(app.into_make_service_with_connect_info::<SocketAddr>())
    .await
    .unwrap();

} ```

# Configuration presets

Instead of using the configuration builder you can use predefined presets.