Skip to content

Commit

Permalink
Upgrade to pmtiles, rm async-trait in a trait (#1300)
Browse files Browse the repository at this point in the history
* Bump to pmtiles that doesn't use `async_trait` crate
* `trait SourceConfigExtras` no longer needs `#[async_trait]`
  • Loading branch information
nyurik authored Apr 11, 2024
1 parent e89e90f commit 99db6d7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mbtiles = { path = "./mbtiles", version = "0.9.0" }
moka = { version = "0.12", features = ["future"] }
num_cpus = "1"
pbf_font_tools = { version = "2.5.1", features = ["freetype"] }
pmtiles = { version = "0.8", features = ["http-async", "mmap-async-tokio", "tilejson", "reqwest-rustls-tls-native-roots"] }
pmtiles = { version = "0.9", features = ["http-async", "mmap-async-tokio", "tilejson", "reqwest-rustls-tls-native-roots"] }
postgis = "0.9"
postgres = { version = "0.19", features = ["with-time-0_3", "with-uuid-1", "with-serde_json-1"] }
postgres-protocol = "0.6"
Expand Down
15 changes: 11 additions & 4 deletions martin/src/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::fmt::Debug;
use std::mem;
use std::path::{Path, PathBuf};

use async_trait::async_trait;
use futures::TryFutureExt;
use log::{info, warn};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -61,15 +60,23 @@ pub trait ConfigExtras: Clone + Debug + Default + PartialEq + Send {
fn get_unrecognized(&self) -> &UnrecognizedValues;
}

#[async_trait]
pub trait SourceConfigExtras: ConfigExtras {
#[must_use]
fn parse_urls() -> bool {
false
}
async fn new_sources(&self, id: String, path: PathBuf) -> FileResult<Box<dyn Source>>;

async fn new_sources_url(&self, id: String, url: Url) -> FileResult<Box<dyn Source>>;
fn new_sources(
&self,
id: String,
path: PathBuf,
) -> impl std::future::Future<Output = FileResult<Box<dyn Source>>> + Send;

fn new_sources_url(
&self,
id: String,
url: Url,
) -> impl std::future::Future<Output = FileResult<Box<dyn Source>>> + Send;
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
Expand Down
4 changes: 3 additions & 1 deletion martin/src/mbtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ impl ConfigExtras for MbtConfig {
}
}

#[async_trait]
impl SourceConfigExtras for MbtConfig {
async fn new_sources(&self, id: String, path: PathBuf) -> FileResult<Box<dyn Source>> {
Ok(Box::new(MbtSource::new(id, path).await?))
}

// TODO: Remove #[allow] after switching to Rust/Clippy v1.78+ in CI
// See https://github.com/rust-lang/rust-clippy/pull/12323
#[allow(clippy::no_effect_underscore_binding)]
async fn new_sources_url(&self, _id: String, _url: Url) -> FileResult<Box<dyn Source>> {
unreachable!()
}
Expand Down
3 changes: 1 addition & 2 deletions martin/src/pmtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl PmtCache {
}
}

#[async_trait]
impl DirectoryCache for PmtCache {
async fn get_dir_entry(&self, offset: usize, tile_id: u64) -> DirCacheResult {
if let Some(dir) = get_cached_value!(&self.cache, CacheValue::PmtDirectory, {
Expand Down Expand Up @@ -129,7 +128,7 @@ impl ConfigExtras for PmtConfig {
&self.unrecognized
}
}
#[async_trait]

impl SourceConfigExtras for PmtConfig {
fn parse_urls() -> bool {
true
Expand Down
2 changes: 0 additions & 2 deletions martin/src/sprites/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::{BTreeMap, HashMap};
use std::fmt::Debug;
use std::path::PathBuf;

use async_trait::async_trait;
use futures::future::try_join_all;
use log::{info, warn};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -65,7 +64,6 @@ pub struct SpriteConfig {
pub unrecognized: UnrecognizedValues,
}

#[async_trait]
impl ConfigExtras for SpriteConfig {
fn get_unrecognized(&self) -> &UnrecognizedValues {
&self.unrecognized
Expand Down

0 comments on commit 99db6d7

Please sign in to comment.