#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Reserved {
pub author: String,
pub bytes: u64,
pub hold: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Refused {
pub reason: String,
pub message: String,
}
pub trait Quota: Send + Sync {
fn reserve(&self, author: &str, bytes: u64) -> Result<Reserved, String>;
fn commit(&self, reserved: Reserved);
fn reserve_count(&self, author: &str) -> Result<Reserved, String> {
Ok(Reserved { author: author.to_string(), bytes: 0, hold: None })
}
fn moved(&self, _author: &str, _delta: i64) {}
fn reserve_question(&self, author: &str) -> Result<Reserved, Refused> {
Ok(Reserved { author: author.to_string(), bytes: 0, hold: None })
}
fn release(&self, _reserved: Reserved) {}
}
#[derive(Debug, Clone, Copy, Default)]
pub struct AllowAll;
impl Quota for AllowAll {
fn reserve(&self, author: &str, bytes: u64) -> Result<Reserved, String> {
Ok(Reserved { author: author.to_string(), bytes, hold: None })
}
fn commit(&self, _reserved: Reserved) {}
}