use crate::catnip::runtime::memory::consts::{
DEFAULT_BODY_POOL_SIZE,
DEFAULT_CACHE_SIZE,
DEFAULT_MAX_BODY_SIZE,
};
#[derive(Debug)]
pub struct MemoryConfig {
max_body_size: usize,
body_pool_size: usize,
cache_size: usize,
}
impl MemoryConfig {
pub fn new(max_body_size: Option<usize>, body_pool_size: Option<usize>, cache_size: Option<usize>) -> Self {
let mut config: Self = Self::default();
if let Some(max_body_size) = max_body_size {
config.max_body_size = max_body_size;
}
if let Some(body_pool_size) = body_pool_size {
config.body_pool_size = body_pool_size;
}
if let Some(cache_size) = cache_size {
config.cache_size = cache_size;
}
config
}
pub fn get_max_body_size(&self) -> usize {
self.max_body_size
}
pub fn get_body_pool_size(&self) -> usize {
self.body_pool_size
}
pub fn get_cache_size(&self) -> usize {
self.cache_size
}
}
impl Default for MemoryConfig {
fn default() -> Self {
Self {
max_body_size: DEFAULT_MAX_BODY_SIZE,
body_pool_size: DEFAULT_BODY_POOL_SIZE,
cache_size: DEFAULT_CACHE_SIZE,
}
}
}