quota 0.1.2

High-performance Rate-limiter
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::{QuotaPool, QuotaResult, StaleQuotaRef};

pub struct QuotaRef<'a> {
    pub(crate) pool: &'a QuotaPool<'a>,
    pub(crate) index: usize,
    pub(crate) generation: u32,
}

impl<'a> QuotaRef<'a> {
    #[inline]
    pub fn consume(&self, cost: u64) -> Result<QuotaResult, StaleQuotaRef> {
        self.pool.consume_at(self.index, self.generation, cost)
    }
}

#[cfg(test)]
mod tests;