martin-core 0.18.0

Basic building blocks of MapLibre's Martin tile server.
Documentation
//! Catalog for managing tile source metadata and discovery.
//!
//! Provides a type-safe catalog system for storing and retrieving tile source
//! information, including content types, encoding, and attribution data.

use std::collections::BTreeMap;

use jiff::Timestamp;
use serde::{Deserialize, Serialize};
use serde_with;

/// A catalog mapping source IDs to their metadata entries.
///
/// Used to store and discover available tile sources with their associated
/// metadata like content types, names, and attribution information.
///
/// # Examples
///
/// ```rust
/// use martin_core::tiles::catalog::{TileCatalog, CatalogSourceEntry};
///
/// let mut catalog = TileCatalog::new();
/// let mut entry = CatalogSourceEntry::default();
/// entry.content_type = "application/x-protobuf".to_string();
/// entry.content_encoding = Some("gzip".to_string());
/// entry.name = Some("My Tiles".to_string());
/// catalog.insert("my_source".to_string(), entry);
/// ```
pub type TileCatalog = BTreeMap<String, CatalogSourceEntry>;

/// Metadata for a tile source in the catalog.
///
/// Contains information needed to properly serve tiles from a source,
/// including HTTP headers and human-readable metadata.
#[serde_with::skip_serializing_none]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(feature = "unstable-schemas", derive(schemars::JsonSchema, utoipa::ToSchema))]
#[non_exhaustive]
pub struct CatalogSourceEntry {
    /// MIME type for the tile data (e.g., "application/x-protobuf", "image/png")
    pub content_type: String,
    /// Optional content encoding (e.g., "gzip", "deflate")
    pub content_encoding: Option<String>,
    /// Human-readable name for the tile source
    pub name: Option<String>,
    /// Description of the tile source content
    pub description: Option<String>,
    /// Attribution text for the data source
    pub attribution: Option<String>,
    /// Tile grid the source is served in, when it is not the default Web Mercator grid
    pub tile_grid: Option<String>,
    /// Number of vector layers declared by this source.
    pub layer_count: Option<u32>,
    /// Timestamp of the underlying source's last modification.
    #[cfg_attr(feature = "unstable-schemas", schemars(with = "Option<String>", extend("format" = "date-time")))]
    pub last_modified_at: Option<Timestamp>,
}