lint pmtiles macro call

This commit is contained in:
Yuri Astrakhan 2023-12-23 22:02:32 -05:00
parent ea2b934d70
commit a68ebcdf5b
4 changed files with 27 additions and 30 deletions

4
Cargo.lock generated
View File

@ -2498,9 +2498,9 @@ dependencies = [
[[package]] [[package]]
name = "pmtiles" name = "pmtiles"
version = "0.5.1" version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7de79041fd108a8650835812b262675027ef19a81336c7a5d7375b2e4ae45762" checksum = "2c0b1fa428f190cde32998618ceb127c6596bcc2902f6f8bc0ade1e2db35b58d"
dependencies = [ dependencies = [
"async-compression", "async-compression",
"async-recursion", "async-recursion",

View File

@ -1,4 +1,4 @@
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Formatter};
use std::io; use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Arc; use std::sync::Arc;
@ -13,12 +13,19 @@ use pmtiles::{Compression, TileType};
use tilejson::TileJSON; use tilejson::TileJSON;
use crate::file_config::FileError::{InvalidMetadata, IoError}; 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::pmtiles::impl_pmtiles_source;
use crate::source::{Source, UrlQuery}; use crate::source::{Source, UrlQuery};
use crate::{MartinResult, TileCoord, TileData}; use crate::{MartinResult, TileCoord, TileData};
impl_pmtiles_source!(PmtFileSource, MmapBackend, NoCache, PathBuf); impl_pmtiles_source!(
PmtFileSource,
MmapBackend,
NoCache,
PathBuf,
Path::display,
InvalidMetadata
);
impl PmtFileSource { impl PmtFileSource {
pub async fn new_box(id: String, path: PathBuf) -> FileResult<Box<dyn Source>> { pub async fn new_box(id: String, path: PathBuf) -> FileResult<Box<dyn Source>> {
@ -48,12 +55,4 @@ impl PmtFileSource {
Self::new_int(id, path, reader).await 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)
}
} }

View File

@ -1,4 +1,5 @@
use std::fmt::{Debug, Display, Formatter}; use std::convert::identity;
use std::fmt::{Debug, Formatter};
use std::sync::Arc; use std::sync::Arc;
use async_trait::async_trait; 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 { impl PmtHttpSource {
pub async fn new_url_box(id: String, url: Url) -> FileResult<Box<dyn Source>> { pub async fn new_url_box(id: String, url: Url) -> FileResult<Box<dyn Source>> {
@ -58,12 +66,4 @@ impl PmtHttpSource {
Self::new_int(id, url, reader).await 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)
}
} }

View File

@ -5,7 +5,7 @@ pub use file_pmtiles::PmtFileSource;
pub use http_pmtiles::PmtHttpSource; pub use http_pmtiles::PmtHttpSource;
macro_rules! impl_pmtiles_source { 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)] #[derive(Clone)]
pub struct $name { pub struct $name {
id: String, id: String,
@ -36,7 +36,7 @@ macro_rules! impl_pmtiles_source {
let hdr = &reader.get_header(); let hdr = &reader.get_header();
if hdr.tile_type != TileType::Mvt && hdr.tile_compression != Compression::None { if hdr.tile_type != TileType::Mvt && hdr.tile_compression != Compression::None {
return Err(Self::metadata_err( return Err($err(
format!( format!(
"Format {:?} and compression {:?} are not yet supported", "Format {:?} and compression {:?} are not yet supported",
hdr.tile_type, hdr.tile_compression hdr.tile_type, hdr.tile_compression
@ -53,7 +53,7 @@ macro_rules! impl_pmtiles_source {
Compression::Unknown => { Compression::Unknown => {
warn!( warn!(
"MVT tiles have unknown compression in file {}", "MVT tiles have unknown compression in file {}",
Self::display_path(&path) $display_path(&path)
); );
Encoding::Uncompressed Encoding::Uncompressed
} }
@ -66,15 +66,13 @@ macro_rules! impl_pmtiles_source {
TileType::Png => Format::Png.into(), TileType::Png => Format::Png.into(),
TileType::Jpeg => Format::Jpeg.into(), TileType::Jpeg => Format::Jpeg.into(),
TileType::Webp => Format::Webp.into(), TileType::Webp => Format::Webp.into(),
TileType::Unknown => { TileType::Unknown => return Err($err("Unknown tile type".to_string(), path)),
return Err(Self::metadata_err("Unknown tile type".to_string(), path))
}
}; };
let tilejson = reader.parse_tilejson(Vec::new()).await.unwrap_or_else(|e| { let tilejson = reader.parse_tilejson(Vec::new()).await.unwrap_or_else(|e| {
warn!( warn!(
"{e:?}: Unable to parse metadata for {}", "{e:?}: Unable to parse metadata for {}",
Self::display_path(&path) $display_path(&path)
); );
hdr.get_tilejson(Vec::new()) hdr.get_tilejson(Vec::new())
}); });