Macro tilejson::tilejson

source ·
macro_rules! tilejson {
    ( tilejson: $ver:expr, tiles: $sources:expr $(, $tag:tt : $val:expr)* $(,)? ) => { ... };
    ( tiles: $sources:expr $(, $tag:tt : $val:expr)* $(,)? ) => { ... };
    ( $tile_source:expr $(, $tag:tt : $val:expr)* $(,)? ) => { ... };
}
Expand description

Use this macro to create a TileJSON struct with optional values. The tilejson! macro can be used in several ways:

With a single tile source

// The tile source is auto-converted to a vector
let tj = tilejson! { "https://example.com/".to_string() };
assert_eq!(tj.tiles[0], "https://example.com/");
assert_eq!(tj.tilejson, "3.0.0");
assert_eq!(tj.minzoom, None);

// With optional values
let tj = tilejson! { "https://example.com/".to_string(), minzoom: 1, maxzoom: 2 };
assert_eq!(tj.tiles[0], "https://example.com/");
assert_eq!(tj.minzoom, Some(1));
assert_eq!(tj.maxzoom, Some(2));

With multiple tile sources and an optional version

// Could use any number of tile sources here
let tj = tilejson! { tiles: vec!["https://example.com/".to_string()] };
assert_eq!(tj.tiles[0], "https://example.com/");

// With the optional tilejson version (must be used in this order)
let tj = tilejson! { tilejson: "2.1.0".to_string(), tiles: vec!["https://example.com/".to_string()], };
assert_eq!(tj.tiles[0], "https://example.com/");
assert_eq!(tj.tilejson, "2.1.0");

// Other optional values could be used at the end
let tj = tilejson! { tiles: vec!["https://example.com/".to_string()], minzoom: 5 };
assert_eq!(tj.tiles[0], "https://example.com/");
assert_eq!(tj.tilejson, "3.0.0");
assert_eq!(tj.minzoom, Some(5));

// version and optional values together
let tj = tilejson! { tilejson: "2.2.0".to_string(), tiles: vec!["https://example.com/".to_string()], minzoom: 5 };
assert_eq!(tj.tiles[0], "https://example.com/");
assert_eq!(tj.tilejson, "2.2.0");
assert_eq!(tj.minzoom, Some(5));