use rocket::serde::Deserialize;
use std::fs;
#[derive(Clone, Debug, Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct Config {
pub directory: String,
pub port: usize,
pub wmts: Vec<TileConfig>,
pub xyz: Vec<TileConfig>,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct TileConfig {
pub alias: String,
pub url: String,
}
impl Config {
pub fn from_file(filepath: &str) -> Config {
let toml_str = fs::read_to_string(filepath)
.unwrap_or_else(|_| panic!("Failed to read \"{}\".", filepath));
toml::from_str(&toml_str)
.unwrap_or_else(|_| panic!("Failed to deserialize \"{}\".", filepath))
}
}