diff --git a/Cargo.lock b/Cargo.lock index df3123c1..3bbc11a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2498,9 +2498,9 @@ dependencies = [ [[package]] name = "pmtiles" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de79041fd108a8650835812b262675027ef19a81336c7a5d7375b2e4ae45762" +checksum = "2c0b1fa428f190cde32998618ceb127c6596bcc2902f6f8bc0ade1e2db35b58d" dependencies = [ "async-compression", "async-recursion", diff --git a/martin/src/pmtiles/file_pmtiles.rs b/martin/src/pmtiles/file_pmtiles.rs index 42d833f7..2790d831 100644 --- a/martin/src/pmtiles/file_pmtiles.rs +++ b/martin/src/pmtiles/file_pmtiles.rs @@ -1,4 +1,4 @@ -use std::fmt::{Debug, Display, Formatter}; +use std::fmt::{Debug, Formatter}; use std::io; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -13,12 +13,19 @@ use pmtiles::{Compression, TileType}; use tilejson::TileJSON; use crate::file_config::FileError::{InvalidMetadata, IoError}; -use crate::file_config::{FileError, FileResult}; +use crate::file_config::FileResult; use crate::pmtiles::impl_pmtiles_source; use crate::source::{Source, UrlQuery}; use crate::{MartinResult, TileCoord, TileData}; -impl_pmtiles_source!(PmtFileSource, MmapBackend, NoCache, PathBuf); +impl_pmtiles_source!( + PmtFileSource, + MmapBackend, + NoCache, + PathBuf, + Path::display, + InvalidMetadata +); impl PmtFileSource { pub async fn new_box(id: String, path: PathBuf) -> FileResult> { @@ -48,12 +55,4 @@ impl PmtFileSource { Self::new_int(id, path, reader).await } - - fn display_path(path: &Path) -> impl Display + '_ { - path.display() - } - - fn metadata_err(message: String, path: PathBuf) -> FileError { - InvalidMetadata(message, path) - } } diff --git a/martin/src/pmtiles/http_pmtiles.rs b/martin/src/pmtiles/http_pmtiles.rs index fe419a88..922c2818 100644 --- a/martin/src/pmtiles/http_pmtiles.rs +++ b/martin/src/pmtiles/http_pmtiles.rs @@ -1,4 +1,5 @@ -use std::fmt::{Debug, Display, Formatter}; +use std::convert::identity; +use std::fmt::{Debug, Formatter}; use std::sync::Arc; use async_trait::async_trait; @@ -41,7 +42,14 @@ impl DirectoryCache for PmtCache { } } -impl_pmtiles_source!(PmtHttpSource, HttpBackend, PmtCache, Url); +impl_pmtiles_source!( + PmtHttpSource, + HttpBackend, + PmtCache, + Url, + identity, + InvalidUrlMetadata +); impl PmtHttpSource { pub async fn new_url_box(id: String, url: Url) -> FileResult> { @@ -58,12 +66,4 @@ impl PmtHttpSource { Self::new_int(id, url, reader).await } - - fn display_path(path: &Url) -> impl Display + '_ { - path - } - - fn metadata_err(message: String, path: Url) -> FileError { - InvalidUrlMetadata(message, path) - } } diff --git a/martin/src/pmtiles/mod.rs b/martin/src/pmtiles/mod.rs index cf3462b4..30e72209 100644 --- a/martin/src/pmtiles/mod.rs +++ b/martin/src/pmtiles/mod.rs @@ -5,7 +5,7 @@ pub use file_pmtiles::PmtFileSource; pub use http_pmtiles::PmtHttpSource; macro_rules! impl_pmtiles_source { - ($name: ident, $backend: ty, $cache: ty, $path: ty) => { + ($name: ident, $backend: ty, $cache: ty, $path: ty, $display_path: path, $err: ident) => { #[derive(Clone)] pub struct $name { id: String, @@ -36,7 +36,7 @@ macro_rules! impl_pmtiles_source { let hdr = &reader.get_header(); if hdr.tile_type != TileType::Mvt && hdr.tile_compression != Compression::None { - return Err(Self::metadata_err( + return Err($err( format!( "Format {:?} and compression {:?} are not yet supported", hdr.tile_type, hdr.tile_compression @@ -53,7 +53,7 @@ macro_rules! impl_pmtiles_source { Compression::Unknown => { warn!( "MVT tiles have unknown compression in file {}", - Self::display_path(&path) + $display_path(&path) ); Encoding::Uncompressed } @@ -66,15 +66,13 @@ macro_rules! impl_pmtiles_source { TileType::Png => Format::Png.into(), TileType::Jpeg => Format::Jpeg.into(), TileType::Webp => Format::Webp.into(), - TileType::Unknown => { - return Err(Self::metadata_err("Unknown tile type".to_string(), path)) - } + TileType::Unknown => return Err($err("Unknown tile type".to_string(), path)), }; let tilejson = reader.parse_tilejson(Vec::new()).await.unwrap_or_else(|e| { warn!( "{e:?}: Unable to parse metadata for {}", - Self::display_path(&path) + $display_path(&path) ); hdr.get_tilejson(Vec::new()) });