mirror of
https://github.com/maplibre/martin.git
synced 2024-12-18 20:31:54 +03:00
lint pmtiles macro call
This commit is contained in:
parent
ea2b934d70
commit
a68ebcdf5b
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -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",
|
||||
|
@ -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<Box<dyn Source>> {
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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<Box<dyn Source>> {
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user