mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-25 23:00:03 +00:00
Optimize and generalize find_version
- Rm the process of collecting into `BTreeMap` in `find_version`. - Accept any type that implements trait `Version` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
b2d09e2b13
commit
e308b275d5
2 changed files with 38 additions and 44 deletions
|
@ -34,22 +34,8 @@ pub async fn fetch_crate_cratesio(
|
|||
})?;
|
||||
|
||||
// Locate matching version
|
||||
let version_iter =
|
||||
base_info
|
||||
.versions
|
||||
.iter()
|
||||
.filter_map(|v| if !v.yanked { Some(&v.num) } else { None });
|
||||
let version_name = find_version(version_req, version_iter)?;
|
||||
|
||||
// Fetch information for the filtered version
|
||||
let version = base_info
|
||||
.versions
|
||||
.iter()
|
||||
.find(|v| v.num == version_name.to_string())
|
||||
.ok_or_else(|| BinstallError::VersionUnavailable {
|
||||
crate_name: name.into(),
|
||||
v: version_name.clone(),
|
||||
})?;
|
||||
let version_iter = base_info.versions.iter().filter(|v| !v.yanked);
|
||||
let (version, version_name) = find_version(version_req, version_iter)?;
|
||||
|
||||
debug!("Found information for crate version: '{}'", version.num);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue