use crate::{Error, Result};
#[non_exhaustive]
#[derive(Debug, Clone, Copy)]
pub struct Limits {
pub header: usize,
pub key_index: usize,
pub compressed: usize,
pub block: usize,
pub record: usize,
pub entries: usize,
pub blocks: usize,
pub metadata: usize,
pub cache: usize,
pub redirects: usize,
pub fuzzy_cells: usize,
}
impl Default for Limits {
fn default() -> Self {
Self {
header: 16 * 1024 * 1024,
key_index: 64 * 1024 * 1024,
compressed: 64 * 1024 * 1024,
block: 64 * 1024 * 1024,
record: 64 * 1024 * 1024,
entries: 10_000_000,
blocks: 1_000_000,
metadata: 256 * 1024 * 1024,
cache: 64 * 1024 * 1024,
redirects: 32,
fuzzy_cells: 4_000_000,
}
}
}
impl Limits {
pub fn check(kind: &'static str, actual: u64, limit: usize) -> Result<()> {
if actual > limit as u64 {
return Err(Error::Limit {
kind,
actual,
limit: limit as u64,
});
}
Ok(())
}
}