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;