How to implement rate limiting in async Rust

Implement async rate limiting in Rust using the governor crate with Arc and Mutex for shared state.

Use the governor crate with Arc<Mutex<RateLimiter>> to share state across async tasks. Add the dependency, initialize the limiter, and check it before processing requests.

use governor::{Quota, RateLimiter};
use std::sync::{Arc, Mutex};

let limiter = Arc::new(Mutex::new(RateLimiter::direct(Quota::per_second(10))));
let limiter_clone = limiter.clone();

let task = async move {
    if limiter_clone.lock().unwrap().check().is_err() {
        return Err("Rate limit exceeded");
    }
    Ok(())
};