use crate::{Config, State};
use serde::de::DeserializeOwned;
pub struct ConfigRegistrar {
pub register: fn(&State, &Config) -> (),
}
impl ConfigRegistrar {
pub const fn new(register: fn(&State, &Config) -> ()) -> Self {
Self { register }
}
}
inventory::collect!(ConfigRegistrar);
pub trait ConfigItem: DeserializeOwned + Clone + Send + Sync + 'static {
fn toml_key() -> &'static str;
fn register(state: &State, config: &Config) {
let config_item = config.get::<Self>().unwrap_or_else(|_| {
panic!(
"Failed to load config item '{}' from the configuration file",
Self::toml_key()
)
});
state.insert(config_item);
}
}