use fizzyx_sys as sys;
use std::rc::Rc;
pub const DEFAULT_MEMORY_PAGES_LIMIT: u32 = sys::FizzyMemoryPagesLimitDefault;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Config {
memory_pages_limit: u32,
}
impl Default for Config {
fn default() -> Self {
Self {
memory_pages_limit: DEFAULT_MEMORY_PAGES_LIMIT,
}
}
}
impl Config {
pub fn new() -> Self {
Self::default()
}
pub fn memory_pages_limit(&mut self, pages: u32) -> &mut Self {
self.memory_pages_limit = pages.min(65536);
self
}
pub fn get_memory_pages_limit(&self) -> u32 {
self.memory_pages_limit
}
}
#[derive(Debug, Clone)]
pub struct Engine {
inner: Rc<Config>,
}
impl Default for Engine {
fn default() -> Self {
Self::new(&Config::default())
}
}
impl Engine {
pub fn new(config: &Config) -> Self {
Self {
inner: Rc::new(*config),
}
}
pub fn config(&self) -> &Config {
&self.inner
}
pub(crate) fn memory_pages_limit(&self) -> u32 {
self.inner.memory_pages_limit
}
}