1use rocket::serde::Deserialize;
4use std::fs;
5
6#[derive(Clone, Debug, Deserialize)]
8#[serde(crate = "rocket::serde")]
9pub struct Config {
10 pub directory: String,
11 pub port: usize,
12 pub wmts: Vec<TileConfig>,
13 pub xyz: Vec<TileConfig>,
14}
15
16#[derive(Clone, Debug, Deserialize)]
18#[serde(crate = "rocket::serde")]
19pub struct TileConfig {
20 pub alias: String,
22 pub url: String,
24}
25
26impl Config {
27 pub fn from_file(filepath: &str) -> Config {
29 let toml_str = fs::read_to_string(filepath)
30 .unwrap_or_else(|_| panic!("Failed to read \"{}\".", filepath));
31
32 toml::from_str(&toml_str)
33 .unwrap_or_else(|_| panic!("Failed to deserialize \"{}\".", filepath))
34 }
35}