Tower Rate Limit Layer
use tower::limit::RateLimitLayer;
let service = ServiceBuilder::new()
.layer(RateLimitLayer::new(100, Duration::from_secs(1)))
.service(my_service);
tower::limit::RateLimitLayer uses a simple token refill mechanism internally.
For production use, tower-governor wraps the governor crate (GCRA algorithm — more precise than naive token bucket):
use tower_governor::GovernorLayer;
let service = ServiceBuilder::new()
.layer(GovernorLayer::new(governor_config))
.service(my_service);