Skip to content

Commit 97e8e49

Browse files
committed
feat(utils): resurrect the AlpmExt trait
This required fixing `find_local_satisfier` which wasn't compiling. This module had been previously left out of the module tree, so the broken code was never compiled and thus never detected.
1 parent 9c005e6 commit 97e8e49

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

alpm-utils/src/alpm.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
use crate::depends::satisfies_ver;
2+
use alpm::{Alpm, Depend, Package, Result};
23

3-
use alpm::{Alpm, Result, Package, Depend};
4-
4+
/// Extension methods to the [`Alpm`] type.
55
pub trait AlpmExt {
6-
fn find_local_satisfier<S: Into<String>>(&self, pkg: S) -> Result<Option<Package>>;
6+
/// Try to find a [`Package`] that satisfies a given dependency.
7+
fn find_local_satisfier<S>(&self, pkg: S) -> Result<Option<Package>>
8+
where
9+
S: Into<String>;
710
}
811

912
impl AlpmExt for Alpm {
10-
fn find_local_satisfier<S: Into<String>>(&self, pkg: S) -> Result<Option<Package>> {
13+
fn find_local_satisfier<S>(&self, pkg: S) -> Result<Option<Package>>
14+
where
15+
S: Into<String>,
16+
{
1117
let localdb = self.localdb();
1218
let pkg = pkg.into();
1319

14-
if let Ok(alpm_pkg) = localdb.pkg(&pkg) {
15-
if satisfies_ver(&Depend::new(&pkg), alpm_pkg.version()) {
20+
if let Ok(alpm_pkg) = localdb.pkg(pkg.as_str()) {
21+
if satisfies_ver(Depend::new(pkg.as_str()), alpm_pkg.version()) {
1622
return Ok(Some(alpm_pkg));
1723
}
1824
}
1925

20-
return Ok(localdb.pkgs()?.find_satisfier(pkg));
26+
Ok(localdb.pkgs().find_satisfier(pkg))
2127
}
2228
}

alpm-utils/src/depends.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
use alpm::{AsDep, DepModVer, Ver};
22

33
/// Checks if a dependency is satisfied by a package (name + version).
4-
pub fn satisfies_dep<S: AsRef<str>, V: AsRef<Ver>>(
5-
dep: impl AsDep,
6-
name: S,
7-
version: V,
8-
) -> bool {
4+
pub fn satisfies_dep<S: AsRef<str>, V: AsRef<Ver>>(dep: impl AsDep, name: S, version: V) -> bool {
95
let name = name.as_ref();
106
let dep = dep.as_dep();
117

@@ -66,7 +62,7 @@ pub fn satisfies_provide_nover(dep: impl AsDep, provide: impl AsDep) -> bool {
6662
dep.as_dep().name() == provide.as_dep().name()
6763
}
6864

69-
fn satisfies_ver<V: AsRef<Ver>>(dep: impl AsDep, version: V) -> bool {
65+
pub(crate) fn satisfies_ver<V: AsRef<Ver>>(dep: impl AsDep, version: V) -> bool {
7066
let version = version.as_ref();
7167
let dep = dep.as_dep();
7268

alpm-utils/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66

77
#[cfg(feature = "conf")]
88
mod conf;
9+
910
#[cfg(feature = "alpm")]
11+
mod alpm;
1012
mod db;
13+
1114
/// Utils for dependency checking.
1215
#[cfg(feature = "alpm")]
1316
pub mod depends;
1417
mod target;
1518

1619
#[cfg(feature = "conf")]
1720
pub use crate::conf::*;
21+
1822
#[cfg(feature = "alpm")]
23+
pub use crate::alpm::*;
1924
pub use crate::db::*;
2025
pub use crate::target::*;

0 commit comments

Comments
 (0)