Skip to main content

game_kernel_settings/settings/
mod.rs

1use toml::macros::Deserialize;
2use toml::value::Table;
3
4use toml::*;
5
6pub trait ConfigModule {
7    fn get_name() -> &'static str;
8}
9
10pub struct Config {
11    t: Table,
12}
13
14impl Config {
15    pub fn new<T: AsRef<str>>(x: T) -> Self {
16        if let Value::Table(t) = x.as_ref().parse().unwrap() {
17            return Config { t };
18        } else {
19            panic!("...");
20        }
21    }
22
23    fn conf_for_module<'a, T: Deserialize<'a> + ConfigModule>(&mut self) -> T {
24        self.t.remove(T::get_name()).unwrap().try_into().unwrap()
25    }
26}