throttle_lock 0.1.2

Throttle can be used to monitor and limit user activity.
Documentation
  • Coverage
  • 75%
    6 out of 8 items documented1 out of 8 items with examples
  • Size
  • Source code size: 14.51 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.77 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • scripturial/throttle
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • scripturial

Throttle Lock

Throttle is an activity counter that can be used to monitor and limit activity such as incoming connections and sign in attempts.

Disclaimer: This library is not guaranteed and is not warranted to be fit for purpose. This code is not an appropriate replacement for dedicated security software and hardware. For demonstration purposes only.

Examples

Limit calls to an API to 5 per second, or lockout for one minute

use throttle_lock::Throttle;

let mut counter = Throttle::new(1000, 5, 1000*60);
if counter.is_throttled() {
    println!("Try again later")
}

Limit signin attempts on an email address to 5 per minute, or lockout for 5 minutes.

use throttle_lock::ThrottleHash;

let mut counter = ThrottleHash::new(60*1000, 5, 3*60*1000);
let email:String = "john@example.com".to_string();
if counter.is_throttled(&email) {
    println!("Try again later")
}