Skip to content

Commit 0421166

Browse files
committed
fix: revert SupportFn type change
1 parent 6efb248 commit 0421166

File tree

5 files changed

+31
-46
lines changed

5 files changed

+31
-46
lines changed

postgresql_archive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ default = [
5353
]
5454
blocking = ["dep:tokio"]
5555
github = [
56-
"dep:target-triple",
5756
"dep:serde_json",
57+
"dep:target-triple",
5858
]
5959
indicatif = [
6060
"dep:tracing-indicatif"
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
11
use semver::Version;
22

3-
/// Matcher for PostgreSQL binaries from custom GitHub release repositories
4-
/// following the same pattern as <https://github.com/theseus-rs/postgresql-binaries>
3+
/// Matcher for PostgreSQL binaries from custom GitHub release repositories following the same
4+
/// pattern as <https://github.com/theseus-rs/postgresql-binaries>
55
///
66
/// # Errors
77
/// * If the asset matcher fails.
8-
/// TODO: support more custom settings
98
pub fn matcher(_url: &str, name: &str, version: &Version) -> crate::Result<bool> {
109
let target = target_triple::TARGET;
10+
// TODO: consider relaxing the version format to allow for more flexibility in where the version
11+
// and target appear in the filename.
1112
let expected_name = format!("postgresql-{version}-{target}.tar.gz");
1213
Ok(name == expected_name)
1314
}
1415

1516
#[cfg(test)]
1617
mod tests {
17-
use std::sync::Arc;
18-
1918
use super::*;
20-
use crate::{
21-
Result,
22-
matcher::{self, registry::SupportsFn},
23-
};
19+
use crate::{Result, matcher};
20+
21+
const TEST_URL: &str = "https://github.com/owner/repo";
2422

2523
#[test]
2624
fn test_register_custom_repo() -> Result<()> {
27-
let custom_url = "https://github.com/Owner/Repo";
28-
let wrapped_url = Arc::new(custom_url.to_string());
29-
let supports_fn: SupportsFn = Box::new(move |url| Ok(url == wrapped_url.as_str()));
25+
#[expect(clippy::unnecessary_wraps)]
26+
fn supports_fn(url: &str) -> Result<bool> {
27+
Ok(url == TEST_URL)
28+
}
3029
matcher::registry::register(supports_fn, matcher)?;
3130

32-
let matcher = matcher::registry::get(custom_url)?;
31+
let matcher = matcher::registry::get(TEST_URL)?;
3332
let version = Version::new(16, 3, 0);
3433
let expected_name = format!("postgresql-{}-{}.tar.gz", version, target_triple::TARGET);
3534
assert!(matcher("", &expected_name, &version)?);
36-
3735
Ok(())
3836
}
3937
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
pub mod custom;
12
#[cfg(feature = "theseus")]
23
pub mod theseus;
34
#[cfg(feature = "zonky")]
45
pub mod zonky;
5-
pub mod custom;

postgresql_archive/src/matcher/registry.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::sync::{Arc, LazyLock, Mutex, RwLock};
1010
static REGISTRY: LazyLock<Arc<Mutex<MatchersRegistry>>> =
1111
LazyLock::new(|| Arc::new(Mutex::new(MatchersRegistry::default())));
1212

13-
pub type SupportsFn = Box<dyn Fn(&str) -> Result<bool> + Send + Sync + 'static>;
13+
pub type SupportsFn = fn(&str) -> Result<bool>;
1414
pub type MatcherFn = fn(&str, &str, &Version) -> Result<bool>;
1515

1616
/// Singleton struct to store matchers
@@ -66,9 +66,9 @@ impl Default for MatchersRegistry {
6666
fn default() -> Self {
6767
let mut registry = Self::new();
6868
#[cfg(feature = "theseus")]
69-
registry.register(Box::new(|url| Ok(url == theseus::URL)), theseus::matcher);
69+
registry.register(|url| Ok(url == theseus::URL), theseus::matcher);
7070
#[cfg(feature = "zonky")]
71-
registry.register(Box::new(|url| Ok(url == zonky::URL)), zonky::matcher);
71+
registry.register(|url| Ok(url == zonky::URL), zonky::matcher);
7272
registry
7373
}
7474
}
@@ -78,14 +78,12 @@ impl Default for MatchersRegistry {
7878
///
7979
/// # Errors
8080
/// * If the registry is poisoned.
81-
pub fn register<F>(supports_fn: F, matcher_fn: MatcherFn) -> Result<()>
82-
where
83-
F: Fn(&str) -> Result<bool> + Send + Sync + 'static,
84-
{
81+
pub fn register(supports_fn: SupportsFn, matcher_fn: MatcherFn) -> Result<()>
82+
where {
8583
let mut registry = REGISTRY
8684
.lock()
8785
.map_err(|error| PoisonedLock(error.to_string()))?;
88-
registry.register(Box::new(supports_fn), matcher_fn);
86+
registry.register(supports_fn, matcher_fn);
8987
Ok(())
9088
}
9189

postgresql_embedded/build/bundle.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
use anyhow::Result;
44
use postgresql_archive::configuration::custom;
5-
use postgresql_archive::matcher::registry::SupportsFn;
65
use postgresql_archive::repository::github::repository::GitHub;
76
use postgresql_archive::{VersionReq, matcher};
87
use postgresql_archive::{get_archive, repository};
98
use std::fs::File;
109
use std::io::Write;
1110
use std::path::PathBuf;
1211
use std::str::FromStr;
13-
use std::sync::Arc;
1412
use std::{env, fs};
1513
use url::Url;
1614

@@ -25,13 +23,11 @@ pub(crate) async fn stage_postgresql_archive() -> Result<()> {
2523
let default_releases_url = String::new();
2624

2725
let releases_url = match env::var("POSTGRESQL_RELEASES_URL") {
28-
Ok(custom_url) => {
29-
if !custom_url.is_empty() {
30-
register_github_repository(&custom_url)?;
31-
}
26+
Ok(custom_url) if !default_releases_url.is_empty() => {
27+
register_github_repository()?;
3228
custom_url
3329
}
34-
Err(_) => default_releases_url,
30+
_ => default_releases_url,
3531
};
3632
println!("PostgreSQL releases URL: {releases_url}");
3733
let postgres_version_req = env::var("POSTGRESQL_VERSION").unwrap_or("*".to_string());
@@ -63,21 +59,14 @@ pub(crate) async fn stage_postgresql_archive() -> Result<()> {
6359
Ok(())
6460
}
6561

66-
fn register_github_repository(custom_url: &str) -> Result<()> {
67-
repository::registry::register(
68-
|url| {
69-
let parsed_url = Url::parse(url)?;
70-
let host = parsed_url.host_str().unwrap_or_default();
71-
Ok(host.ends_with("github.com"))
72-
},
73-
Box::new(GitHub::new),
74-
)?;
75-
76-
// make custom_url as Send + Sync + 'static
77-
let custom_url = Arc::new(custom_url.to_string());
78-
let supports_fn: SupportsFn = Box::new(move |url| Ok(url == custom_url.as_str()));
79-
// register the matcher
80-
matcher::registry::register(supports_fn, custom::matcher::matcher)?;
62+
fn supports_github_url(url: &str) -> postgresql_archive::Result<bool> {
63+
let parsed_url = Url::parse(url)?;
64+
let host = parsed_url.host_str().unwrap_or_default();
65+
Ok(host.ends_with("github.com"))
66+
}
8167

68+
fn register_github_repository() -> Result<()> {
69+
repository::registry::register(supports_github_url, Box::new(GitHub::new))?;
70+
matcher::registry::register(supports_github_url, custom::matcher::matcher)?;
8271
Ok(())
8372
}

0 commit comments

Comments
 (0)