use std::{fs, path::Path};
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct Config {
pub async_worker_thread_number: u16,
}
impl Default for Config {
fn default() -> Self {
Self {
async_worker_thread_number: 16,
}
}
}
impl Config {
pub fn create<T: AsRef<Path>>(path: T) -> Self {
let data = fs::read_to_string(path.as_ref()).expect(&format!("failed to load config file {:?}", path.as_ref()));
Self::load_from_str(data.as_str())
}
pub fn load_from_str(toml_str: &str) -> Self {
let config = toml::from_str::<Config>(toml_str).expect("failed to parse the toml str");
config
}
}