pub fn new(size: u64, one_time_burst: u64, complete_refill_time_ms: u64) -> Option<Self> {
        // If either token bucket capacity or refill time is 0, disable limiting.
        if size == 0 || complete_refill_time_ms == 0 {
            return None;
        }
        // Formula for computing current refill amount:
        // refill_token_count = (delta_time * size) / (complete_refill_time_ms * 1_000_000)
        // In order to avoid overflows, simplify the fractions by computing greatest common divisor.

        let complete_refill_time_ns = complete_refill_time_ms * NANOSEC_IN_ONE_MILLISEC;
        // Get the greatest common factor between `size` and `complete_refill_time_ns`.
        let common_factor = gcd(size, complete_refill_time_ns);
        // The division will be exact since `common_factor` is a factor of `size`.
        let processed_capacity: u64 = size / common_factor;
        // The division will be exact since `common_factor` is a factor of `complete_refill_time_ns`.
        let processed_refill_time: u64 = complete_refill_time_ns / common_factor;

        Some(TokenBucket {
            size,
            one_time_burst,
            initial_one_time_burst: one_time_burst,
            refill_time: complete_refill_time_ms,
            // Start off full.
            budget: size,
            // Last updated is now.
            last_update: Instant::now(),
            processed_capacity,
            processed_refill_time,
        })
    }
/// Creates a `TokenBucket` wrapped in an `Option`.
///
/// TokenBucket created is of `size` total capacity and takes `complete_refill_time_ms`
/// milliseconds to go from zero tokens to total capacity. The `one_time_burst` is initial
/// extra credit on top of total capacity, that does not replenish and which can be used
/// for an initial burst of data.
///
/// If the `size` or the `complete refill time` are zero, then `None` is returned.
Creates a `TokenBucket` wrapped in an `Option`.
TokenBucket created is of `size` total capacity and takes `complete_refill_time_ms`
milliseconds to go from zero tokens to total capacity. The `one_time_burst` is initial
extra credit on top of total capacity, that does not replenish and which can be used
for an initial burst of data.


Creates a ` TokenBucket ` wrapped in an ` Option ` . TokenBucket created is of ` size ` total capacity and takes ` complete_refill_time_ms ` milliseconds to go from zero tokens to total capacity . The ` one_time_burst ` is initial extra credit on top of total capacity that does not replenish and which can be used for an initial burst of data .
pub fn new(size: u64, one_time_burst: u64, complete_refill_time_ms: u64) -> Option<Self> {
        // If either token bucket capacity or refill time is 0, disable limiting.
        if size == 0 || complete_refill_time_ms == 0 {
            return None;
        }
        // Formula for computing current refill amount:
        // refill_token_count = (delta_time * size) / (complete_refill_time_ms * 1_000_000)
        // In order to avoid overflows, simplify the fractions by computing greatest common divisor.
        let complete_refill_time_ns = complete_refill_time_ms * NANOSEC_IN_ONE_MILLISEC;
        // Get the greatest common factor between `size` and `complete_refill_time_ns`.
        let common_factor = gcd(size, complete_refill_time_ns);
        // The division will be exact since `common_factor` is a factor of `size`.
        let processed_capacity: u64 = size / common_factor;
        // The division will be exact since `common_factor` is a factor of `complete_refill_time_ns`.
        let processed_refill_time: u64 = complete_refill_time_ns / common_factor;
        Some(TokenBucket {
            size,
            one_time_burst,
            initial_one_time_burst: one_time_burst,
            refill_time: complete_refill_time_ms,
            // Start off full.
            budget: size,
            // Last updated is now.
            last_update: Instant::now(),
            processed_capacity,
            processed_refill_time,
        })
    }
pub fn new ( size : u64 , one_time_burst : u64 , complete_refill_time_ms : u64 ) -> Option < Self > { // If either token bucket capacity or refill time is 0, disable limiting. if size == 0 || complete_refill_time_ms == 0 { return None ; } // Formula for computing current refill amount: // refill_token_count = (delta_time * size) / (complete_refill_time_ms * 1_000_000) // In order to avoid overflows, simplify the fractions by computing greatest common divisor. let complete_refill_time_ns = complete_refill_time_ms * NANOSEC_IN_ONE_MILLISEC ; // Get the greatest common factor between `size` and `complete_refill_time_ns`. let common_factor = gcd ( size , complete_refill_time_ns ) ; // The division will be exact since `common_factor` is a factor of `size`. let processed_capacity : u64 = size / common_factor ; // The division will be exact since `common_factor` is a factor of `complete_refill_time_ns`. let processed_refill_time : u64 = complete_refill_time_ns / common_factor ; Some ( TokenBucket { size , one_time_burst , initial_one_time_burst : one_time_burst , refill_time : complete_refill_time_ms , // Start off full. budget : size , // Last updated is now. last_update : Instant :: now ( ) , processed_capacity , processed_refill_time , } ) }
Creates a `TokenBucket` wrapped in an `Option`.
Creates a ` TokenBucket ` wrapped in an ` Option ` .
size
u64
one_time_burst
u64
complete_refill_time_ms
u64
size
u64
one_time_burst
u64
complete_refill_time_ms
u64