Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unified the types to be based on TileInfoSource #1611

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions martin/src/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::config::{copy_unrecognized_config, UnrecognizedValues};
use crate::file_config::FileError::{
InvalidFilePath, InvalidSourceFilePath, InvalidSourceUrl, IoError,
};
use crate::source::{Source, TileInfoSources};
use crate::source::{TileInfoSource, TileInfoSources};
use crate::utils::{IdResolver, OptMainCache, OptOneMany};
use crate::MartinResult;
use crate::OptOneMany::{Many, One};
Expand Down Expand Up @@ -70,13 +70,13 @@ pub trait SourceConfigExtras: ConfigExtras {
&self,
id: String,
path: PathBuf,
) -> impl std::future::Future<Output = FileResult<Box<dyn Source>>> + Send;
) -> impl std::future::Future<Output = FileResult<TileInfoSource>> + Send;

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

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
Expand Down
8 changes: 4 additions & 4 deletions martin/src/mbtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use url::Url;
use crate::config::UnrecognizedValues;
use crate::file_config::FileError::{AcquireConnError, InvalidMetadata, IoError};
use crate::file_config::{ConfigExtras, FileResult, SourceConfigExtras};
use crate::source::{TileData, UrlQuery};
use crate::source::{TileData, TileInfoSource, UrlQuery};
use crate::{MartinResult, Source};

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
Expand All @@ -30,14 +30,14 @@ impl ConfigExtras for MbtConfig {
}

impl SourceConfigExtras for MbtConfig {
async fn new_sources(&self, id: String, path: PathBuf) -> FileResult<Box<dyn Source>> {
async fn new_sources(&self, id: String, path: PathBuf) -> FileResult<TileInfoSource> {
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>> {
async fn new_sources_url(&self, _id: String, _url: Url) -> FileResult<TileInfoSource> {
unreachable!()
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ impl Source for MbtSource {
self.tile_info
}

fn clone_source(&self) -> Box<dyn Source> {
fn clone_source(&self) -> TileInfoSource {
Box::new(self.clone())
}

Expand Down
4 changes: 2 additions & 2 deletions martin/src/pg/pg_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tilejson::TileJSON;
use crate::pg::pool::PgPool;
use crate::pg::utils::query_to_json;
use crate::pg::PgError::{GetTileError, GetTileWithQueryError, PrepareQueryError};
use crate::source::{Source, TileData, UrlQuery};
use crate::source::{Source, TileData, TileInfoSource, UrlQuery};
use crate::MartinResult;

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Source for PgSource {
TileInfo::new(Mvt, Uncompressed)
}

fn clone_source(&self) -> Box<dyn Source> {
fn clone_source(&self) -> TileInfoSource {
Box::new(self.clone())
}

Expand Down
8 changes: 4 additions & 4 deletions martin/src/pmtiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use url::Url;
use crate::config::UnrecognizedValues;
use crate::file_config::FileError::{InvalidMetadata, InvalidUrlMetadata, IoError};
use crate::file_config::{ConfigExtras, FileError, FileResult, SourceConfigExtras};
use crate::source::UrlQuery;
use crate::source::{TileInfoSource, UrlQuery};
use crate::utils::cache::get_cached_value;
use crate::utils::{CacheKey, CacheValue, OptMainCache};
use crate::{MartinResult, Source, TileData};
Expand Down Expand Up @@ -134,13 +134,13 @@ impl SourceConfigExtras for PmtConfig {
true
}

async fn new_sources(&self, id: String, path: PathBuf) -> FileResult<Box<dyn Source>> {
async fn new_sources(&self, id: String, path: PathBuf) -> FileResult<TileInfoSource> {
Ok(Box::new(
PmtFileSource::new(self.new_cached_source(), id, path).await?,
))
}

async fn new_sources_url(&self, id: String, url: Url) -> FileResult<Box<dyn Source>> {
async fn new_sources_url(&self, id: String, url: Url) -> FileResult<TileInfoSource> {
Ok(Box::new(
PmtHttpSource::new(
self.client.clone().unwrap(),
Expand Down Expand Up @@ -250,7 +250,7 @@ macro_rules! impl_pmtiles_source {
self.tile_info
}

fn clone_source(&self) -> Box<dyn Source> {
fn clone_source(&self) -> TileInfoSource {
Box::new(self.clone())
}

Expand Down
6 changes: 3 additions & 3 deletions martin/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub type TileInfoSource = Box<dyn Source>;
pub type TileInfoSources = Vec<TileInfoSource>;

#[derive(Default, Clone)]
pub struct TileSources(HashMap<String, Box<dyn Source>>);
pub struct TileSources(HashMap<String, TileInfoSource>);
pub type TileCatalog = BTreeMap<String, CatalogSourceEntry>;

impl TileSources {
Expand Down Expand Up @@ -107,7 +107,7 @@ pub trait Source: Send + Debug {

fn get_tile_info(&self) -> TileInfo;

fn clone_source(&self) -> Box<dyn Source>;
fn clone_source(&self) -> TileInfoSource;

fn support_url_query(&self) -> bool {
false
Expand Down Expand Up @@ -139,7 +139,7 @@ pub trait Source: Send + Debug {
}
}

impl Clone for Box<dyn Source> {
impl Clone for TileInfoSource {
fn clone(&self) -> Self {
self.clone_source()
}
Expand Down
4 changes: 2 additions & 2 deletions martin/src/srv/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub mod tests {
use tilejson::TileJSON;

use super::*;
use crate::source::{Source, TileData};
use crate::source::{Source, TileData, TileInfoSource};
use crate::UrlQuery;

#[derive(Debug, Clone)]
Expand All @@ -225,7 +225,7 @@ pub mod tests {
TileInfo::new(Format::Mvt, Encoding::Uncompressed)
}

fn clone_source(&self) -> Box<dyn Source> {
fn clone_source(&self) -> TileInfoSource {
unimplemented!()
}

Expand Down
Loading