Skip to content

Commit

Permalink
lint pmtiles macro call
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Dec 24, 2023
1 parent ea2b934 commit a68ebcd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions martin/src/pmtiles/file_pmtiles.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Box<dyn Source>> {
Expand Down Expand Up @@ -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)
}
}
20 changes: 10 additions & 10 deletions martin/src/pmtiles/http_pmtiles.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Box<dyn Source>> {
Expand All @@ -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)
}
}
12 changes: 5 additions & 7 deletions martin/src/pmtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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())
});
Expand Down

0 comments on commit a68ebcd

Please sign in to comment.