tilemake_rs 0.1.2

Convert osm.pbf files to pmtiles
use std::collections::HashMap;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Layer {
    pub minzoom: u8,
    pub maxzoom: u8,
}

#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Settings {
    pub minzoom: u8,
    pub maxzoom: u8,
    pub basezoom: u8,
    pub include_ids: bool,
    pub compress: String,
    pub name: String,
    pub version: String,
    pub description: String,
}

/// The config that is part of the InputArguments and used for processing
///
/// The structure is borrowed from tilemaker's `config.json`.
///
/// # Example
///
/// ```
/// # #[cfg(feature = "serde")]
/// # {
/// use std::collections::HashMap;
/// use serde_json;
/// use tilemake_rs::Config;
///
/// let json_str = r#"
/// {
///   "layers": {
///     "roads": { "minzoom": 12, "maxzoom": 14 },
///     "buildings": { "minzoom": 14, "maxzoom": 14 }
///   },
///   "settings": {
///     "minzoom": 0,
///     "maxzoom": 1,
///     "basezoom": 1,
///     "include_ids": false,
///     "compress": "gzip",
///     "name": "Example",
///     "version": "0.1",
///     "description": "Example with roads and buildings"
///   }
/// }
/// "#;
///
/// let config = Config::from_json(json_str).unwrap();
/// assert_eq!(config.layers["roads"].minzoom, 12);
/// assert_eq!(config.settings.name, "Example");
/// # }
/// ```
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Config {
    pub layers: HashMap<String, Layer>,
    pub settings: Settings,
}

#[cfg(feature = "serde")]
impl Config {
    /// Deserializes the config from a JSON string
    pub fn from_json(json_str: &str) -> Result<Self, serde_json::Error> {
        serde_json::from_str(json_str)
    }
}