tiles_proxy/
config.rs

1//! Configuration for TilesProxy, deserialized from TOML file.
2
3use rocket::serde::Deserialize;
4use std::fs;
5
6/// Root configuration.
7#[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/// Configuration of a tile server.
17#[derive(Clone, Debug, Deserialize)]
18#[serde(crate = "rocket::serde")]
19pub struct TileConfig {
20    /// Alias for the server.
21    pub alias: String,
22    /// Server URL template.
23    pub url: String,
24}
25
26impl Config {
27    /// Get config from a TOML file.
28    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}