Clippy suggestions

This commit is contained in:
Félix Saparelli 2022-06-01 00:47:32 +12:00
parent 13a8e1e5fe
commit ac74da4a27
No known key found for this signature in database
GPG key ID: B948C4BAE44FC474
6 changed files with 17 additions and 25 deletions

View file

@ -22,7 +22,7 @@ fn find_version<'a, V: Iterator<Item = &'a String>>(
let filtered: BTreeSet<_> = version_iter let filtered: BTreeSet<_> = version_iter
.filter_map(|v| { .filter_map(|v| {
// Remove leading `v` for git tags // Remove leading `v` for git tags
let ver_str = match v.strip_prefix("s") { let ver_str = match v.strip_prefix('s') {
Some(v) => v, Some(v) => v,
None => v, None => v,
}; };
@ -47,7 +47,7 @@ fn find_version<'a, V: Iterator<Item = &'a String>>(
.iter() .iter()
.max() .max()
.cloned() .cloned()
.ok_or_else(|| BinstallError::VersionMismatch { req: version_req }) .ok_or(BinstallError::VersionMismatch { req: version_req })
} }
/// Fetch a crate by name and version from crates.io /// Fetch a crate by name and version from crates.io

View file

@ -54,14 +54,16 @@ impl MultiFetcher {
pub async fn first_available(&self) -> Option<&dyn Fetcher> { pub async fn first_available(&self) -> Option<&dyn Fetcher> {
for fetcher in &self.fetchers { for fetcher in &self.fetchers {
if fetcher.check().await.unwrap_or_else(|err| { let available = fetcher.check().await.unwrap_or_else(|err| {
debug!( debug!(
"Error while checking fetcher {}: {}", "Error while checking fetcher {}: {}",
fetcher.source_name(), fetcher.source_name(),
err err
); );
false false
}) { });
if available {
return Some(&**fetcher); return Some(&**fetcher);
} }
} }

View file

@ -16,7 +16,7 @@ impl GhCrateMeta {
fn url(&self) -> Result<Url, BinstallError> { fn url(&self) -> Result<Url, BinstallError> {
let ctx = Context::from_data(&self.data); let ctx = Context::from_data(&self.data);
debug!("Using context: {:?}", ctx); debug!("Using context: {:?}", ctx);
Ok(ctx.render_url(&self.data.meta.pkg_url)?) ctx.render_url(&self.data.meta.pkg_url)
} }
} }

View file

@ -194,7 +194,7 @@ pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathB
// Local executable dir if no cargo is found // Local executable dir if no cargo is found
if let Some(d) = dirs::executable_dir() { if let Some(d) = dirs::executable_dir() {
debug!("Fallback to {}", d.display()); debug!("Fallback to {}", d.display());
return Some(d.into()); return Some(d);
} }
None None
@ -226,7 +226,7 @@ pub trait Template: Serialize {
let mut tt = TinyTemplate::new(); let mut tt = TinyTemplate::new();
// Add template to instance // Add template to instance
tt.add_template("path", &template)?; tt.add_template("path", template)?;
// Render output // Render output
Ok(tt.render("path", self)?) Ok(tt.render("path", self)?)

View file

@ -16,14 +16,14 @@ pub mod bins;
pub mod fetchers; pub mod fetchers;
/// Compiled target triple, used as default for binary fetching /// Compiled target triple, used as default for binary fetching
pub const TARGET: &'static str = env!("TARGET"); pub const TARGET: &str = env!("TARGET");
/// Default package path template (may be overridden in package Cargo.toml) /// Default package path template (may be overridden in package Cargo.toml)
pub const DEFAULT_PKG_URL: &'static str = pub const DEFAULT_PKG_URL: &str =
"{ repo }/releases/download/v{ version }/{ name }-{ target }-v{ version }.{ archive-format }"; "{ repo }/releases/download/v{ version }/{ name }-{ target }-v{ version }.{ archive-format }";
/// Default binary name template (may be overridden in package Cargo.toml) /// Default binary name template (may be overridden in package Cargo.toml)
pub const DEFAULT_BIN_DIR: &'static str = "{ name }-{ target }-v{ version }/{ bin }{ binary-ext }"; pub const DEFAULT_BIN_DIR: &str = "{ name }-{ target }-v{ version }/{ bin }{ binary-ext }";
/// Binary format enumeration /// Binary format enumeration
#[derive( #[derive(
@ -113,7 +113,7 @@ impl PkgMeta {
/// Target specific overrides for binary installation /// Target specific overrides for binary installation
/// ///
/// Exposed via `[package.metadata.TARGET]` in `Cargo.toml` /// Exposed via `[package.metadata.TARGET]` in `Cargo.toml`
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default)] #[serde(rename_all = "kebab-case", default)]
pub struct PkgOverride { pub struct PkgOverride {
/// URL template override for package downloads /// URL template override for package downloads
@ -126,16 +126,6 @@ pub struct PkgOverride {
pub bin_dir: Option<String>, pub bin_dir: Option<String>,
} }
impl Default for PkgOverride {
fn default() -> Self {
Self {
pkg_url: None,
pkg_fmt: None,
bin_dir: None,
}
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
pub struct BinMeta { pub struct BinMeta {
@ -164,7 +154,7 @@ mod test {
let manifest = load_manifest_path(&manifest_dir).expect("Error parsing metadata"); let manifest = load_manifest_path(&manifest_dir).expect("Error parsing metadata");
let package = manifest.package.unwrap(); let package = manifest.package.unwrap();
let meta = package.metadata.map(|m| m.binstall).flatten().unwrap(); let meta = package.metadata.and_then(|m| m.binstall).unwrap();
assert_eq!(&package.name, "cargo-binstall"); assert_eq!(&package.name, "cargo-binstall");

View file

@ -191,9 +191,8 @@ async fn entry() -> Result<()> {
package package
.metadata .metadata
.as_ref() .as_ref()
.map(|m| m.binstall.clone()) .and_then(|m| m.binstall.clone())
.flatten() .unwrap_or_default(),
.unwrap_or(PkgMeta::default()),
manifest.bin, manifest.bin,
); );
@ -254,6 +253,7 @@ async fn entry() -> Result<()> {
} }
} }
#[allow(clippy::too_many_arguments)]
async fn install_from_package( async fn install_from_package(
binaries: Vec<Product>, binaries: Vec<Product>,
fetcher: &dyn Fetcher, fetcher: &dyn Fetcher,