Skip to content

Commit

Permalink
Revert "2024 rust edition (#1698)"
Browse files Browse the repository at this point in the history
This reverts commit 1deeda8.
  • Loading branch information
CommanderStorm authored Mar 3, 2025
1 parent 1deeda8 commit 1ee9a45
Show file tree
Hide file tree
Showing 58 changed files with 286 additions and 418 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[workspace]
resolver = "3"
resolver = "2"
members = ["martin", "martin-tile-utils", "mbtiles"]

[workspace.package]
edition = "2024"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/maplibre/martin"
rust-version = "1.85"
rust-version = "1.80"
readme = "README.md"
homepage = "https://martin.maplibre.org/"

Expand Down
10 changes: 7 additions & 3 deletions martin-tile-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ pub fn get_zoom_precision(zoom: u8) -> usize {
assert!(zoom < MAX_ZOOM, "zoom {zoom} must be <= {MAX_ZOOM}");
let lng_delta = webmercator_to_wgs84(EARTH_CIRCUMFERENCE / f64::from(1_u32 << zoom), 0.0).0;
let log = lng_delta.log10() - 0.5;
if log > 0.0 { 0 } else { -log.ceil() as usize }
if log > 0.0 {
0
} else {
-log.ceil() as usize
}
}

#[must_use]
Expand Down Expand Up @@ -300,10 +304,10 @@ mod tests {

use std::fs::read;

use Encoding::{Internal, Uncompressed};
use Format::{Jpeg, Json, Png, Webp};
use approx::assert_relative_eq;
use insta::assert_snapshot;
use Encoding::{Internal, Uncompressed};
use Format::{Jpeg, Json, Png, Webp};

use super::*;

Expand Down
4 changes: 2 additions & 2 deletions martin/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use async_trait::async_trait;
use criterion::async_executor::FuturesExecutor;
use criterion::{Criterion, criterion_group, criterion_main};
use criterion::{criterion_group, criterion_main, Criterion};
use martin::srv::DynTileSource;
use martin::{CatalogSourceEntry, MartinResult, Source, TileData, TileSources, UrlQuery};
use martin_tile_utils::{Encoding, Format, TileCoord, TileInfo};
use pprof::criterion::{Output, PProfProfiler};
use tilejson::{TileJSON, tilejson};
use tilejson::{tilejson, TileJSON};

#[derive(Clone, Debug)]
struct NullSource {
Expand Down
18 changes: 9 additions & 9 deletions martin/src/args/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ pub trait Env<'a>: VariableMap<'a> {
#[must_use]
fn get_env_str(&self, key: &str) -> Option<String> {
match self.var_os(key) {
Some(s) => match s.into_string() {
Ok(v) => Some(v),
Err(v) => {
let v = v.to_string_lossy();
warn!(
"Environment variable {key} has invalid unicode. Lossy representation: {v}"
);
None
Some(s) => {
match s.into_string() {
Ok(v) => Some(v),
Err(v) => {
let v = v.to_string_lossy();
warn!("Environment variable {key} has invalid unicode. Lossy representation: {v}");
None
}
}
},
}
None => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion martin/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub use environment::{Env, OsEnv};
#[cfg(feature = "postgres")]
mod pg;
#[cfg(feature = "postgres")]
pub use pg::{BoundsCalcType, DEFAULT_BOUNDS_TIMEOUT, PgArgs};
pub use pg::{BoundsCalcType, PgArgs, DEFAULT_BOUNDS_TIMEOUT};

mod root;
pub use root::{Args, ExtraArgs, MetaArgs};
Expand Down
30 changes: 9 additions & 21 deletions martin/src/args/pg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use crate::args::connections::Arguments;
use crate::args::connections::State::{Ignore, Take};
use crate::args::environment::Env;
use crate::pg::{POOL_SIZE_DEFAULT, PgConfig, PgSslCerts};
use crate::pg::{PgConfig, PgSslCerts, POOL_SIZE_DEFAULT};
use crate::utils::{OptBoolObj, OptOneMany};

// Must match the help string for BoundsType::Quick
Expand Down Expand Up @@ -92,42 +92,32 @@ impl PgArgs {
} = self;

if let Some(value) = default_srid {
info!(
"Overriding configured default SRID to {value} on all Postgres connections because of a CLI parameter"
);
info!("Overriding configured default SRID to {value} on all Postgres connections because of a CLI parameter");
pg_config.iter_mut().for_each(|c| {
c.default_srid = default_srid;
});
}
if let Some(value) = pool_size {
info!(
"Overriding configured pool size to {value} on all Postgres connections because of a CLI parameter"
);
info!("Overriding configured pool size to {value} on all Postgres connections because of a CLI parameter");
pg_config.iter_mut().for_each(|c| {
c.pool_size = pool_size;
});
}
if let Some(value) = auto_bounds {
info!(
"Overriding auto_bounds to {value} on all Postgres connections because of a CLI parameter"
);
info!("Overriding auto_bounds to {value} on all Postgres connections because of a CLI parameter");
pg_config.iter_mut().for_each(|c| {
c.auto_bounds = auto_bounds;
});
}
if let Some(value) = max_feature_count {
info!(
"Overriding maximum feature count to {value} on all Postgres connections because of a CLI parameter"
);
info!("Overriding maximum feature count to {value} on all Postgres connections because of a CLI parameter");
pg_config.iter_mut().for_each(|c| {
c.max_feature_count = max_feature_count;
});
}
if let Some(ref value) = ca_root_file {
info!(
"Overriding root certificate file to {} on all Postgres connections because of a CLI parameter",
value.display()
);
info!("Overriding root certificate file to {} on all Postgres connections because of a CLI parameter",
value.display());
pg_config.iter_mut().for_each(|c| {
c.ssl_certificates.ssl_root_cert.clone_from(&ca_root_file);
});
Expand All @@ -143,9 +133,7 @@ impl PgArgs {
] {
// We don't want to warn about these in case they were used in the config file expansion
if env.has_unused_var(v) {
warn!(
"Environment variable {v} is set, but will be ignored because a configuration file was loaded. Any environment variables can be used inside the config yaml file."
);
warn!("Environment variable {v} is set, but will be ignored because a configuration file was loaded. Any environment variables can be used inside the config yaml file.");
}
}
}
Expand Down Expand Up @@ -225,8 +213,8 @@ mod tests {
use std::path::PathBuf;

use super::*;
use crate::test_utils::{os, some, FauxEnv};
use crate::MartinError;
use crate::test_utils::{FauxEnv, os, some};

#[test]
fn test_extract_conn_strings() {
Expand Down
4 changes: 2 additions & 2 deletions martin/src/args/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::path::PathBuf;
use clap::Parser;
use log::warn;

use crate::MartinError::ConfigAndConnectionsError;
use crate::args::connections::Arguments;
use crate::args::environment::Env;
use crate::args::srv::SrvArgs;
Expand All @@ -15,6 +14,7 @@ use crate::config::Config;
feature = "cog"
))]
use crate::file_config::FileConfigEnum;
use crate::MartinError::ConfigAndConnectionsError;
use crate::MartinResult;
#[cfg(feature = "fonts")]
use crate::OptOneMany;
Expand Down Expand Up @@ -184,9 +184,9 @@ mod tests {
use insta::assert_yaml_snapshot;

use super::*;
use crate::MartinError::UnrecognizableConnections;
use crate::args::PreferredEncoding;
use crate::test_utils::FauxEnv;
use crate::MartinError::UnrecognizableConnections;

fn parse(args: &[&str]) -> MartinResult<(Config, MetaArgs)> {
let args = Args::parse_from(args);
Expand Down
2 changes: 1 addition & 1 deletion martin/src/args/srv.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::ValueEnum;
use serde::{Deserialize, Serialize};

use crate::srv::{KEEP_ALIVE_DEFAULT, LISTEN_ADDRESSES_DEFAULT, SrvConfig};
use crate::srv::{SrvConfig, KEEP_ALIVE_DEFAULT, LISTEN_ADDRESSES_DEFAULT};

#[allow(clippy::doc_markdown)]
#[derive(clap::Args, Debug, PartialEq, Default)]
Expand Down
18 changes: 9 additions & 9 deletions martin/src/bin/martin-cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ use std::time::Duration;

use actix_http::error::ParseError;
use actix_http::test::TestRequest;
use actix_web::http::header::{ACCEPT_ENCODING, AcceptEncoding, Header as _};
use actix_web::http::header::{AcceptEncoding, Header as _, ACCEPT_ENCODING};
use clap::Parser;
use futures::TryStreamExt;
use futures::stream::{self, StreamExt};
use futures::TryStreamExt;
use log::{debug, error, info, log_enabled};
use martin::args::{Args, ExtraArgs, MetaArgs, OsEnv, SrvArgs};
use martin::srv::{DynTileSource, merge_tilejson};
use martin::srv::{merge_tilejson, DynTileSource};
use martin::{
Config, MartinError, MartinResult, ServerState, TileData, TileInfoSource, TileRect,
append_rect, read_config,
append_rect, read_config, Config, MartinError, MartinResult, ServerState, TileData,
TileInfoSource, TileRect,
};
use martin_tile_utils::{TileCoord, TileInfo, bbox_to_xyz};
use mbtiles::UpdateZoomType::GrowOnly;
use martin_tile_utils::{bbox_to_xyz, TileCoord, TileInfo};
use mbtiles::sqlx::SqliteConnection;
use mbtiles::UpdateZoomType::GrowOnly;
use mbtiles::{
CopyDuplicateMode, MbtError, MbtType, MbtTypeCli, Mbtiles, init_mbtiles_schema,
is_empty_database,
init_mbtiles_schema, is_empty_database, CopyDuplicateMode, MbtError, MbtType, MbtTypeCli,
Mbtiles,
};
use tilejson::Bounds;
use tokio::sync::mpsc::channel;
Expand Down
2 changes: 1 addition & 1 deletion martin/src/bin/martin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::Parser;
use log::{error, info, log_enabled};
use martin::args::{Args, OsEnv};
use martin::srv::new_server;
use martin::{Config, MartinResult, read_config};
use martin::{read_config, Config, MartinResult};

const VERSION: &str = env!("CARGO_PKG_VERSION");

Expand Down
2 changes: 1 addition & 1 deletion martin/src/cog/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use url::Url;

use crate::config::UnrecognizedValues;
use crate::file_config::{ConfigExtras, SourceConfigExtras};
use crate::{Source, file_config::FileResult};
use crate::{file_config::FileResult, Source};

use super::source::CogSource;

Expand Down
4 changes: 1 addition & 3 deletions martin/src/cog/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ pub enum CogError {
#[error("Couldn't decode {1} as tiff file: {0}")]
InvalidTiffFile(TiffError, PathBuf),

#[error(
"Requested zoom level {0} from file {1} is out of range. Possible zoom levels are {2} to {3}"
)]
#[error("Requested zoom level {0} from file {1} is out of range. Possible zoom levels are {2} to {3}")]
ZoomOutOfRange(u8, PathBuf, u8, u8),

#[error("Couldn't find any image in the tiff file: {0}")]
Expand Down
4 changes: 2 additions & 2 deletions martin/src/cog/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use tiff::tags::Tag::{self, GdalNodata};

use async_trait::async_trait;
use martin_tile_utils::{Format, TileCoord, TileInfo};
use tilejson::{TileJSON, tilejson};
use tilejson::{tilejson, TileJSON};

use crate::file_config::FileError;
use crate::{MartinResult, Source, TileData, UrlQuery, file_config::FileResult};
use crate::{file_config::FileResult, MartinResult, Source, TileData, UrlQuery};

use super::CogError;

Expand Down
13 changes: 9 additions & 4 deletions martin/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::ffi::OsStr;
use std::fs::File;
use std::future::Future;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::pin::Pin;
Expand All @@ -10,7 +11,6 @@ use log::info;
use serde::{Deserialize, Serialize};
use subst::VariableMap;

use crate::MartinError::{ConfigLoadError, ConfigParseError, ConfigWriteError, NoSources};
#[cfg(any(
feature = "mbtiles",
feature = "pmtiles",
Expand All @@ -23,8 +23,9 @@ use crate::fonts::FontSources;
use crate::source::{TileInfoSources, TileSources};
#[cfg(feature = "sprites")]
use crate::sprites::{SpriteConfig, SpriteSources};
use crate::srv::{RESERVED_KEYWORDS, SrvConfig};
use crate::utils::{CacheValue, MainCache, OptMainCache, init_aws_lc_tls, parse_base_path};
use crate::srv::{SrvConfig, RESERVED_KEYWORDS};
use crate::utils::{init_aws_lc_tls, parse_base_path, CacheValue, MainCache, OptMainCache};
use crate::MartinError::{ConfigLoadError, ConfigParseError, ConfigWriteError, NoSources};
#[cfg(any(feature = "fonts", feature = "postgres"))]
use crate::OptOneMany;
use crate::{IdResolver, MartinResult};
Expand Down Expand Up @@ -126,7 +127,11 @@ impl Config {
#[cfg(feature = "fonts")]
let is_empty = is_empty && self.fonts.is_empty();

if is_empty { Err(NoSources) } else { Ok(res) }
if is_empty {
Err(NoSources)
} else {
Ok(res)
}
}

pub async fn resolve(&mut self) -> MartinResult<ServerState> {
Expand Down
10 changes: 5 additions & 5 deletions martin/src/file_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use log::{info, warn};
use serde::{Deserialize, Serialize};
use url::Url;

use crate::MartinResult;
use crate::OptOneMany::{Many, One};
use crate::config::{UnrecognizedValues, copy_unrecognized_config};
use crate::config::{copy_unrecognized_config, UnrecognizedValues};
use crate::file_config::FileError::{
InvalidFilePath, InvalidSourceFilePath, InvalidSourceUrl, IoError,
};
use crate::source::{TileInfoSource, TileInfoSources};
use crate::utils::{IdResolver, OptMainCache, OptOneMany};
use crate::MartinResult;
use crate::OptOneMany::{Many, One};

pub type FileResult<T> = Result<T, FileError>;

Expand Down Expand Up @@ -74,13 +74,13 @@ pub trait SourceConfigExtras: ConfigExtras {
&self,
id: String,
path: PathBuf,
) -> impl Future<Output = FileResult<TileInfoSource>> + Send;
) -> impl std::future::Future<Output = FileResult<TileInfoSource>> + Send;

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

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
Expand Down
6 changes: 2 additions & 4 deletions martin/src/fonts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use itertools::Itertools as _;
use log::{debug, info, warn};
use pbf_font_tools::freetype::{Face, Library};
use pbf_font_tools::protobuf::Message;
use pbf_font_tools::{Fontstack, Glyphs, PbfFontError, render_sdf_glyph};
use pbf_font_tools::{render_sdf_glyph, Fontstack, Glyphs, PbfFontError};
use regex::Regex;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -45,9 +45,7 @@ pub enum FontError {
)]
InvalidFontRangeEnd(u32),

#[error(
"Given font range {0}-{1} is invalid. It must be {CP_RANGE_SIZE} characters long (e.g. 0-255, 256-511, ...)"
)]
#[error("Given font range {0}-{1} is invalid. It must be {CP_RANGE_SIZE} characters long (e.g. 0-255, 256-511, ...)")]
InvalidFontRange(u32, u32),

#[error(transparent)]
Expand Down
6 changes: 3 additions & 3 deletions martin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![forbid(unsafe_code)]

mod config;
pub use config::{Config, ServerState, read_config};
pub use config::{read_config, Config, ServerState};

mod source;
pub use source::{
Expand All @@ -11,8 +11,8 @@ pub use source::{

mod utils;
pub use utils::{
IdResolver, MartinError, MartinResult, NO_MAIN_CACHE, OptBoolObj, OptOneMany, TileRect,
append_rect,
append_rect, IdResolver, MartinError, MartinResult, OptBoolObj, OptOneMany, TileRect,
NO_MAIN_CACHE,
};

pub mod args;
Expand Down
Loading

0 comments on commit 1ee9a45

Please sign in to comment.