diff --git a/crates/libscoop/src/bucket.rs b/crates/libscoop/src/bucket.rs index 8a02c05..8d1bdd6 100644 --- a/crates/libscoop/src/bucket.rs +++ b/crates/libscoop/src/bucket.rs @@ -43,7 +43,7 @@ impl Bucket { .map(|n| n.to_str().unwrap().to_string()) .unwrap(); if !path.exists() { - return Err(Error::BucketNotFound(name.clone())); + return Err(Error::BucketNotFound(name)); } let mut remote_url = None; @@ -58,12 +58,10 @@ impl Bucket { let mut dtype = BucketDirectoryType::V2; let entries = nested_dir.read_dir()?; - for entry in entries { - if let Ok(entry) = entry { - if entry.path().is_dir() { - dtype = BucketDirectoryType::V3; - break; - } + for entry in entries.flatten() { + if entry.path().is_dir() { + dtype = BucketDirectoryType::V3; + break; } } dtype @@ -129,8 +127,7 @@ impl Bucket { let json_files = match self.dtype { BucketDirectoryType::V1 => { let path = self.path.as_path(); - let entries = path - .read_dir()? + path.read_dir()? .par_bridge() .filter_map(std::io::Result::ok) .filter(|de| { @@ -140,13 +137,11 @@ impl Bucket { path.is_file() && name.ends_with(".json") && name != "package.json" }) .map(|de| de.path()) - .collect::>(); - entries + .collect::>() } BucketDirectoryType::V2 => { let path = self.path.join("bucket"); - let entries = path - .read_dir()? + path.read_dir()? .par_bridge() .filter_map(std::io::Result::ok) .filter(|de| { @@ -155,13 +150,11 @@ impl Bucket { path.is_file() && name.ends_with(".json") }) .map(|de| de.path()) - .collect::>(); - entries + .collect::>() } BucketDirectoryType::V3 => { let path = self.path.join("bucket"); - let entries = path - .read_dir()? + path.read_dir()? .par_bridge() .filter_map(std::io::Result::ok) .filter(|de| { @@ -185,8 +178,7 @@ impl Bucket { Ok(entries) }) .flatten() - .collect::>(); - entries + .collect::>() } }; Ok(json_files) diff --git a/crates/libscoop/src/cache.rs b/crates/libscoop/src/cache.rs index e8e5ccd..446768f 100644 --- a/crates/libscoop/src/cache.rs +++ b/crates/libscoop/src/cache.rs @@ -13,7 +13,7 @@ impl CacheFile { pub fn from(path: PathBuf) -> Fallible { let text = path.file_name().unwrap().to_str().unwrap(); match REGEX_CACHE_FILE.is_match(text) { - false => Err(Error::InvalidCacheFile { path }.into()), + false => Err(Error::InvalidCacheFile { path }), true => Ok(CacheFile { path }), } } @@ -27,19 +27,19 @@ impl CacheFile { /// Get file name of this cache file #[inline] pub fn file_name(&self) -> &str { - &self.path.file_name().unwrap().to_str().unwrap() + self.path.file_name().unwrap().to_str().unwrap() } /// Get package name of this cache file #[inline] pub fn package_name(&self) -> &str { - self.file_name().split_once("#").map(|s| s.0).unwrap() + self.file_name().split_once('#').map(|s| s.0).unwrap() } /// Get version of this cache file #[inline] pub fn version(&self) -> &str { - self.file_name().splitn(3, "#").collect::>()[1] + self.file_name().splitn(3, '#').collect::>()[1] } /// Get the tmp path of this cache file diff --git a/crates/libscoop/src/config.rs b/crates/libscoop/src/config.rs index 8c92c4d..797f5a5 100644 --- a/crates/libscoop/src/config.rs +++ b/crates/libscoop/src/config.rs @@ -146,14 +146,14 @@ impl Config { true => self.use_external_7zip = None, false => match value.parse::() { Ok(value) => self.use_external_7zip = Some(value), - Err(_) => return Err(Error::InvalidConfigValue(value.to_owned()).into()), + Err(_) => return Err(Error::InvalidConfigValue(value.to_owned())), }, }, "aria2_enabled" | "aria2-enabled" => match is_unset { true => self.aria2_enabled = None, false => match value.parse::() { Ok(value) => self.aria2_enabled = Some(value), - Err(_) => return Err(Error::InvalidConfigValue(value.to_owned()).into()), + Err(_) => return Err(Error::InvalidConfigValue(value.to_owned())), }, }, "cat_style" => { @@ -178,17 +178,17 @@ impl Config { true => self.use_lessmsi = None, false => match value.parse::() { Ok(value) => self.use_lessmsi = Some(value), - Err(_) => return Err(Error::InvalidConfigValue(value.to_owned()).into()), + Err(_) => return Err(Error::InvalidConfigValue(value.to_owned())), }, }, "proxy" => match value { "" | "none" => self.proxy = None, _ => self.proxy = Some(value.to_string()), }, - key => return Err(Error::InvalidConfigKey(key.to_owned()).into()), + key => return Err(Error::InvalidConfigKey(key.to_owned())), } - Ok(self.commit()?) + self.commit() } /// Commit config changes and save to the config file diff --git a/crates/libscoop/src/constant.rs b/crates/libscoop/src/constant.rs index 0bf858c..c4b348d 100644 --- a/crates/libscoop/src/constant.rs +++ b/crates/libscoop/src/constant.rs @@ -71,7 +71,7 @@ static REGEX_ARCHIVE_ZSTD: Lazy = Lazy::new(|| { pub static SPDX_LIST: Lazy> = Lazy::new(|| { // Reference: https://github.com/spdx/license-list-data - const ID_LIST: [&'static str; 458] = [ + const ID_LIST: [&str; 458] = [ "0BSD", "AAL", "ADSL", diff --git a/crates/libscoop/src/event.rs b/crates/libscoop/src/event.rs index ff2d634..26fe81c 100644 --- a/crates/libscoop/src/event.rs +++ b/crates/libscoop/src/event.rs @@ -52,6 +52,12 @@ impl EventBus { } } +impl Default for EventBus { + fn default() -> Self { + Self::new() + } +} + /// Event that may be emitted during the execution of operations. #[derive(Debug, Clone)] #[non_exhaustive] diff --git a/crates/libscoop/src/internal/dag.rs b/crates/libscoop/src/internal/dag.rs index e836c2f..4b2dadb 100644 --- a/crates/libscoop/src/internal/dag.rs +++ b/crates/libscoop/src/internal/dag.rs @@ -147,7 +147,7 @@ where .filter(|(_, deps)| deps.len() == 0) .map(|(node, _)| node) .next() - .map(|node| node.clone()); + .cloned(); if node.is_some() { Self::__unregister(&mut self.nodes, node.as_ref().unwrap()); } @@ -169,9 +169,9 @@ where /// graph. pub fn check(&self) -> Result<()> { let mut nodes = self.nodes.clone(); - while nodes.len() > 0 { + while !nodes.is_empty() { let step = Self::__step(&mut nodes); - if step.len() == 0 { + if step.is_empty() { return Err(CyclicError::from(&nodes)); } } @@ -182,9 +182,9 @@ where /// be returned when cyclic dependency is detected. pub fn walk(&mut self) -> Result>> { let mut res = vec![]; - while self.nodes.len() > 0 { + while !self.nodes.is_empty() { let step = self.step(); - if step.len() == 0 { + if step.is_empty() { return Err(CyclicError::from(&self.nodes)); } res.push(step); @@ -216,17 +216,17 @@ where #[inline] fn __register(nodes: &mut Nodes, node: T, dep_node: Option) { // register node - match nodes.entry(node.clone()) { + match nodes.entry(node) { Entry::Vacant(e) => { let mut dep = Dependencies::new(); if let Some(dep_node) = &dep_node { - drop(dep.insert(dep_node.clone())); + dep.insert(dep_node.clone()); } - drop(e.insert(dep)); + e.insert(dep); } Entry::Occupied(e) => { if let Some(dep_node) = &dep_node { - drop(e.into_mut().insert(dep_node.clone())); + e.into_mut().insert(dep_node.clone()); } } } @@ -234,7 +234,7 @@ where if let Some(dep_node) = dep_node { match nodes.entry(dep_node) { Entry::Vacant(e) => { - drop(e.insert(Dependencies::new())); + e.insert(Dependencies::new()); } Entry::Occupied(_) => { // no-op @@ -245,9 +245,9 @@ where #[inline] fn __unregister(nodes: &mut Nodes, node: &T) { - drop(nodes.remove(node)); + nodes.remove(node); nodes.iter_mut().for_each(|(_, deps)| { - drop(deps.remove(node)); + deps.remove(node); }); } } diff --git a/crates/libscoop/src/internal/git.rs b/crates/libscoop/src/internal/git.rs index 04febd9..defbe51 100644 --- a/crates/libscoop/src/internal/git.rs +++ b/crates/libscoop/src/internal/git.rs @@ -10,7 +10,7 @@ fn fetch_options(proxy: Option<&str>) -> FetchOptions<'static> { cb.credentials( move |url, username, cred| -> Result { let user = username.unwrap_or("git"); - let ref cfg = git2::Config::open_default()?; + let cfg = &(git2::Config::open_default()?); if cred.contains(CredentialType::USERNAME) { git2::Cred::username(user) @@ -26,8 +26,8 @@ fn fetch_options(proxy: Option<&str>) -> FetchOptions<'static> { fo.remote_callbacks(cb); - if proxy.is_some() { - let mut proxy = proxy.unwrap().to_owned(); + if let Some(proxy) = proxy { + let mut proxy = proxy.to_owned(); if !(proxy.starts_with("http") || proxy.starts_with("socks")) { proxy.insert_str(0, "http://"); diff --git a/crates/libscoop/src/internal/mod.rs b/crates/libscoop/src/internal/mod.rs index 6bf666e..0e849ae 100644 --- a/crates/libscoop/src/internal/mod.rs +++ b/crates/libscoop/src/internal/mod.rs @@ -27,7 +27,7 @@ pub fn os_is_arch64() -> bool { /// Check if a given executable is available on the system. pub fn is_program_available(exe: &str) -> bool { if let Ok(path) = std::env::var("PATH") { - for p in path.split(";") { + for p in path.split(';') { let path = Path::new(p).join(exe); if std::fs::metadata(path).is_ok() { return true; @@ -51,46 +51,41 @@ pub fn compare_versions>(ver_a: S, ver_b: S) -> std::cmp::Ordering // ver_a_parsed, ver_b_parsed // ); - loop { - match ver_a_parsed.next() { - Some(a_part) => { - match ver_b_parsed.next() { - Some(b_part) => { - if a_part.parse::().is_ok() { - if b_part.parse::().is_ok() { - let a_part_num = a_part.parse::().unwrap(); - let b_part_num = b_part.parse::().unwrap(); + for a_part in ver_a_parsed { + match ver_b_parsed.next() { + Some(b_part) => { + if a_part.parse::().is_ok() { + if b_part.parse::().is_ok() { + let a_part_num = a_part.parse::().unwrap(); + let b_part_num = b_part.parse::().unwrap(); - match a_part_num { - n if n < b_part_num => return std::cmp::Ordering::Less, - n if n > b_part_num => return std::cmp::Ordering::Greater, - _ => continue, - } - } - - // I guess this should be ok for cases like: 1.2.0 vs. 1.2-rc4 - // num to text comparsion is an interesting branch. - return std::cmp::Ordering::Greater; + match a_part_num { + n if n < b_part_num => return std::cmp::Ordering::Less, + n if n > b_part_num => return std::cmp::Ordering::Greater, + _ => continue, } - - // FIXME: text to text comparsion is the hardest part, - // I just return `Ordering::Equal` currently... } - None => { - if a_part.parse::().is_ok() { - let a_part_num = a_part.parse::().unwrap(); - if 0 == a_part_num { - continue; - } - } else { - return std::cmp::Ordering::Less; - } - return std::cmp::Ordering::Greater; + // I guess this should be ok for cases like: 1.2.0 vs. 1.2-rc4 + // num to text comparsion is an interesting branch. + return std::cmp::Ordering::Greater; + } + + // FIXME: text to text comparsion is the hardest part, + // I just return `Ordering::Equal` currently... + } + None => { + if a_part.parse::().is_ok() { + let a_part_num = a_part.parse::().unwrap(); + if 0 == a_part_num { + continue; } + } else { + return std::cmp::Ordering::Less; } + + return std::cmp::Ordering::Greater; } - None => break, } } @@ -108,13 +103,18 @@ pub fn extract_name_and_bucket(path: &Path) -> Fallible<(String, String)> { Some(caps) => { let name = caps.name("name").map(|m| m.as_str().to_string()); let bucket = caps.name("bucket").map(|m| m.as_str().to_string()); - if name.is_some() && bucket.is_some() { - return Ok((name.unwrap(), bucket.unwrap())); + if let Some(name) = name { + if let Some(bucket) = bucket { + return Ok((name, bucket)); + } } } } - Err(Error::Custom(format!("unsupported manifest path {}", path.display())).into()) + Err(Error::Custom(format!( + "unsupported manifest path {}", + path.display() + ))) } /// Normalize a path, removing things like `.` and `..`. diff --git a/crates/libscoop/src/internal/network.rs b/crates/libscoop/src/internal/network.rs index 0885eea..07d95d3 100644 --- a/crates/libscoop/src/internal/network.rs +++ b/crates/libscoop/src/internal/network.rs @@ -5,8 +5,8 @@ pub fn get_content_length(url: &str, proxy: Option<&str>) -> Option { let mut easy = Easy::new(); easy.get(true).unwrap(); easy.url(url).unwrap(); - if proxy.is_some() { - easy.proxy(proxy.unwrap()).unwrap(); + if let Some(proxy) = proxy { + easy.proxy(proxy).unwrap(); } easy.nobody(true).unwrap(); easy.follow_location(true).unwrap(); diff --git a/crates/libscoop/src/operation.rs b/crates/libscoop/src/operation.rs index 85abc46..8869bf7 100644 --- a/crates/libscoop/src/operation.rs +++ b/crates/libscoop/src/operation.rs @@ -52,9 +52,9 @@ pub fn bucket_add(session: &Session, name: &str, remote_url: &str) -> Fallible<( } let proxy = config.proxy(); - let remote_url = match "" != remote_url { - true => remote_url, - false => crate::constant::BUILTIN_BUCKET_LIST + let remote_url = match remote_url.is_empty() { + false => remote_url, + true => crate::constant::BUILTIN_BUCKET_LIST .iter() .find(|&&(n, _)| n == name) .map(|&(_, remote)| remote) @@ -110,7 +110,7 @@ pub fn bucket_update(session: &Session) -> Fallible<()> { for bucket in buckets.iter() { let repo = bucket.path().to_owned(); - if repo.join(".git").exists() != true { + if !repo.join(".git").exists() { debug!("ignored non-git bucket {}", bucket.name()); continue; } @@ -130,14 +130,12 @@ pub fn bucket_update(session: &Session) -> Fallible<()> { match git::reset_head(repo, proxy) { Ok(_) => { *flag.lock().unwrap() = true; - if emitter.is_some() { - let tx = emitter.unwrap(); + if let Some(tx) = emitter { let _ = tx.send(Event::BucketUpdateSuccessed(name)); } } Err(err) => { - if emitter.is_some() { - let tx = emitter.unwrap(); + if let Some(tx) = emitter { let ctx: BucketUpdateFailedCtx = BucketUpdateFailedCtx { name: name.clone(), err_msg: err.to_string(), @@ -160,8 +158,7 @@ pub fn bucket_update(session: &Session) -> Fallible<()> { config.set("last_update", time.as_str())?; } - if emitter.is_some() { - let tx = emitter.unwrap(); + if let Some(tx) = emitter { let _ = tx.send(Event::BucketUpdateFinished); } Ok(()) @@ -294,8 +291,7 @@ pub fn package_sync( let queries = HashSet::<&str>::from_iter(queries); let emitter = session.emitter(); - if emitter.is_some() { - let tx = emitter.clone().unwrap(); + if let Some(tx) = emitter.clone() { let _ = tx.send(Event::PackageResolveStart); } @@ -321,32 +317,26 @@ pub fn package_sync( continue; } - let emitter = session.emitter(); - - if emitter.is_some() { + if let Some(tx) = emitter.clone() { println!( "{}", pkg.iter().map(|p| p.ident()).collect::>().join(" ") ); let question = pkg.iter().map(|p| p.ident()).collect::>(); - let tx = emitter.unwrap(); if tx.send(Event::SelectPackage(question)).is_ok() { let rx = session.event_bus().inner_receiver(); while let Ok(answer) = rx.recv() { - match answer { - Event::SelectPackageAnswer(idx) => { - println!("{}", idx); - if idx < pkg.len() { - pkg = vec![pkg[idx].clone()]; - break; - } else { - return Err(Error::Custom(format!( - "Invalid package index: {}", - idx - ))); - } + if let Event::SelectPackageAnswer(idx) = answer { + println!("{}", idx); + if idx < pkg.len() { + pkg = vec![pkg[idx].clone()]; + break; + } else { + return Err(Error::Custom(format!( + "Invalid package index: {}", + idx + ))); } - _ => {} } } } @@ -378,7 +368,7 @@ pub fn package_sync( .filter(|p| !p.is_strictly_installed()) .collect::>(); - if packages.len() == 0 { + if packages.is_empty() { return Ok(()); } @@ -394,8 +384,7 @@ pub fn package_sync( println!(" {}", pkg.ident()); } - if emitter.is_some() { - let tx = emitter.unwrap(); + if let Some(tx) = emitter { let _ = tx.send(Event::PackageDownloadSizingStart); } @@ -425,8 +414,8 @@ pub fn package_sync( } for (mut url, _) in urls_mapped_files.into_iter() { - if url.contains("#") { - url = url.split_once("#").unwrap().0; + if url.contains('#') { + url = url.split_once('#').unwrap().0; } let size = internal::network::get_content_length(url, proxy); diff --git a/crates/libscoop/src/package/manifest.rs b/crates/libscoop/src/package/manifest.rs index 1b3d772..ea692cd 100644 --- a/crates/libscoop/src/package/manifest.rs +++ b/crates/libscoop/src/package/manifest.rs @@ -349,7 +349,7 @@ impl<'de, T: Deserialize<'de>> Deserialize<'de> for Vectorized { } T::deserialize(serde_json::Value::Object(remap)) .map(|val| vec![val]) - .map_err(|e| de::Error::custom(e)) + .map_err(de::Error::custom) } } @@ -413,7 +413,7 @@ impl<'de> Deserialize<'de> for License { "url" => url = Some(value), _ => { // skip invalid fields - let _ = map.next_value()?; + map.next_value()?; continue; } } @@ -423,7 +423,7 @@ impl<'de> Deserialize<'de> for License { } } - Ok(deserializer.deserialize_any(LicenseVisitor)?) + deserializer.deserialize_any(LicenseVisitor) } } @@ -445,7 +445,7 @@ impl<'de> Deserialize<'de> for Sourceforge { where E: de::Error, { - let (project, path) = match s.split_once("/") { + let (project, path) = match s.split_once('/') { Some((a, b)) => (Some(a.to_owned()), b.to_owned()), None => (None, s.to_owned()), }; @@ -465,7 +465,7 @@ impl<'de> Deserialize<'de> for Sourceforge { "path" => path = Ok(value), _ => { // skip invalid fields - let _ = map.next_value()?; + map.next_value()?; continue; } } @@ -478,7 +478,7 @@ impl<'de> Deserialize<'de> for Sourceforge { } } - Ok(deserializer.deserialize_any(SourceforgeVisitor)?) + deserializer.deserialize_any(SourceforgeVisitor) } } @@ -549,7 +549,7 @@ impl<'de> Deserialize<'de> for Checkver { "sourceforge" => sourceforge = Some(map.next_value()?), _ => { // skip invalid fields - let _ = map.next_value()?; + map.next_value()?; continue; } } @@ -569,7 +569,7 @@ impl<'de> Deserialize<'de> for Checkver { } } - Ok(deserializer.deserialize_any(CheckverVisitor)?) + deserializer.deserialize_any(CheckverVisitor) } } @@ -583,9 +583,9 @@ where if let Some(hashes) = Option::>::deserialize(deserializer)? { // validate hashes for hash in hashes.0.iter().map(|s| s.as_str()) { - if !REGEX_HASH.is_match(&hash) { + if !REGEX_HASH.is_match(hash) { return Err(de::Error::invalid_value( - de::Unexpected::Str(&hash), + de::Unexpected::Str(hash), &"a valid hash string", )); } @@ -754,9 +754,7 @@ impl Manifest { pub fn supported_arch(&self) -> Vec { let mut ret = vec![]; - let arch = self.architecture(); - if arch.is_some() { - let arch = arch.unwrap(); + if let Some(arch) = self.architecture() { if arch.ia32.is_some() { ret.push("ia32".to_string()); } @@ -969,7 +967,7 @@ impl Installer { #[inline] pub fn file(&self) -> Option<&str> { - self.file.as_ref().map(|s| s.as_str()) + self.file.as_deref() } #[inline] @@ -991,7 +989,7 @@ impl Uninstaller { #[inline] pub fn file(&self) -> Option<&str> { - self.file.as_ref().map(|s| s.as_str()) + self.file.as_deref() } #[inline] diff --git a/crates/libscoop/src/package/mod.rs b/crates/libscoop/src/package/mod.rs index 7c20c4c..9010160 100644 --- a/crates/libscoop/src/package/mod.rs +++ b/crates/libscoop/src/package/mod.rs @@ -60,7 +60,7 @@ pub struct InstallStateInstalled { impl InstallStateInstalled { #[inline] pub fn bucket(&self) -> Option<&str> { - self.bucket.as_ref().map(|s| s.as_str()) + self.bucket.as_deref() } #[inline] @@ -70,7 +70,7 @@ impl InstallStateInstalled { #[inline] pub fn url(&self) -> Option<&str> { - self.url.as_ref().map(|s| s.as_str()) + self.url.as_deref() } #[inline] @@ -197,13 +197,10 @@ impl Package { pub fn upgradable(&self) -> Option<&str> { let origin_pkg = self.upgradable.borrow(); - match origin_pkg { - None => None, - Some(inner) => match inner { - None => None, - Some(pkg) => Some(pkg.version()), - }, + if let Some(Some(pkg)) = origin_pkg { + return Some(pkg.version()); } + None } /// Get the version of this package. diff --git a/crates/libscoop/src/package/query.rs b/crates/libscoop/src/package/query.rs index ae298b7..7e02f83 100644 --- a/crates/libscoop/src/package/query.rs +++ b/crates/libscoop/src/package/query.rs @@ -60,7 +60,7 @@ impl Matcher for RegexMatcher { pub(crate) fn query_installed( session: &Session, query: &str, - options: &Vec, + options: &[QueryOption], ) -> Fallible> { let is_explicit_mode = options.contains(&QueryOption::Explicit); let is_wildcard_query = query.eq("*") || query.is_empty(); @@ -70,8 +70,8 @@ pub(crate) fn query_installed( let mut matcher: Vec<(Option, Box)> = vec![]; if !is_wildcard_query { - if query.contains("/") { - let (bucket_prefix, name) = query.split_once("/").unwrap(); + if query.contains('/') { + let (bucket_prefix, name) = query.split_once('/').unwrap(); if is_explicit_mode { matcher.push(( @@ -85,22 +85,19 @@ pub(crate) fn query_installed( .build()?; matcher.push((Some(bucket_prefix.to_owned()), Box::new(RegexMatcher(re)))); } + } else if is_explicit_mode { + matcher.push((None, Box::new(ExplicitMatcher(query)))); } else { - if is_explicit_mode { - matcher.push((None, Box::new(ExplicitMatcher(query)))); - } else { - let re = RegexBuilder::new(query) - .case_insensitive(true) - .multi_line(true) - .build()?; - matcher.push((None, Box::new(RegexMatcher(re)))); - } + let re = RegexBuilder::new(query) + .case_insensitive(true) + .multi_line(true) + .build()?; + matcher.push((None, Box::new(RegexMatcher(re)))); } } let packages = apps_dir .read_dir()? - .into_iter() .par_bridge() .filter_map(|item| { if let Ok(e) = item { @@ -212,7 +209,7 @@ pub(crate) fn query_installed( } let mut bucket_path = root_path.join("buckets"); - bucket_path.push(&bucket); + bucket_path.push(bucket); if let Ok(origin_bucket) = Bucket::from(&bucket_path) { let origin_manifest_path = origin_bucket.path_of_manifest(name); @@ -266,7 +263,7 @@ pub(crate) fn query_installed( pub(crate) fn query_synced( session: &Session, query: &str, - options: &Vec, + options: &[QueryOption], ) -> Fallible> { let is_explicit_mode = options.contains(&QueryOption::Explicit); let is_wildcard_query = query.eq("*") || query.is_empty(); @@ -276,8 +273,8 @@ pub(crate) fn query_synced( let mut matcher: Vec<(Option, Box)> = vec![]; if !is_wildcard_query { - if query.contains("/") { - let (bucket_prefix, name) = query.split_once("/").unwrap(); + if query.contains('/') { + let (bucket_prefix, name) = query.split_once('/').unwrap(); if is_explicit_mode { matcher.push(( @@ -291,16 +288,14 @@ pub(crate) fn query_synced( .build()?; matcher.push((Some(bucket_prefix.to_owned()), Box::new(RegexMatcher(re)))); } + } else if is_explicit_mode { + matcher.push((None, Box::new(ExplicitMatcher(query)))); } else { - if is_explicit_mode { - matcher.push((None, Box::new(ExplicitMatcher(query)))); - } else { - let re = RegexBuilder::new(query) - .case_insensitive(true) - .multi_line(true) - .build()?; - matcher.push((None, Box::new(RegexMatcher(re)))); - } + let re = RegexBuilder::new(query) + .case_insensitive(true) + .multi_line(true) + .build()?; + matcher.push((None, Box::new(RegexMatcher(re)))); } } diff --git a/crates/libscoop/src/package/resolve.rs b/crates/libscoop/src/package/resolve.rs index 1ba799c..bd605bd 100644 --- a/crates/libscoop/src/package/resolve.rs +++ b/crates/libscoop/src/package/resolve.rs @@ -73,7 +73,7 @@ pub(crate) fn resolve_dependencies(session: &Session, packages: &mut Vec) -> Fallible<()> { let mut to_resolve = packages.clone(); - let installed = query::query_installed(session, "*", &vec![QueryOption::Explicit])?; + let installed = query::query_installed(session, "*", &[QueryOption::Explicit])?; loop { if to_resolve.is_empty() { break; diff --git a/src/clap_app.rs b/src/clap_app.rs index bba6f31..3c87b09 100644 --- a/src/clap_app.rs +++ b/src/clap_app.rs @@ -1,7 +1,7 @@ use clap::{crate_description, crate_name, crate_version, Arg, ArgAction, Command}; pub fn build() -> Command { - let app = Command::new(crate_name!()) + Command::new(crate_name!()) .version(crate_version!()) .about(crate_description!()) .after_help(format!( @@ -271,7 +271,7 @@ pub fn build() -> Command { .short('e') .long("explicit") .action(ArgAction::SetTrue) - .conflicts_with_all(&["with-description", "with-binary"]), + .conflicts_with_all(["with-description", "with-binary"]), ) .arg( Arg::new("with-binary") @@ -317,7 +317,5 @@ pub fn build() -> Command { Command::new("upgrade") .about("Upgrade installed package(s)") .arg(Arg::new("package").help("Specified package(s) to be upgraded")), - ); - - app + ) } diff --git a/src/cmd/cache.rs b/src/cmd/cache.rs index 18d4639..32e74aa 100644 --- a/src/cmd/cache.rs +++ b/src/cmd/cache.rs @@ -98,11 +98,9 @@ fn filesize(length: u64, with_unit: bool) -> String { } else { j.to_string() } + } else if with_unit { + format!("{} B", flength) } else { - if with_unit { - format!("{} B", flength) - } else { - flength.to_string() - } + flength.to_string() } } diff --git a/src/cmd/cat.rs b/src/cmd/cat.rs index 133719b..72c41ca 100644 --- a/src/cmd/cat.rs +++ b/src/cmd/cat.rs @@ -30,7 +30,7 @@ pub fn cmd_cat(matches: &ArgMatches, session: &Session) -> Result<()> { let mut child = Command::new("cmd") .arg("/C") .arg(cat) - .arg(&package.manfest_path()) + .arg(package.manfest_path()) .args(cat_args) .spawn()?; child.wait()?; @@ -56,7 +56,7 @@ pub fn cmd_cat(matches: &ArgMatches, session: &Session) -> Result<()> { /// Check if a given executable is available on the system fn is_program_available(exe: &str) -> bool { if let Ok(path) = std::env::var("PATH") { - for p in path.split(";") { + for p in path.split(';') { let path = Path::new(p).join(exe); if std::fs::metadata(path).is_ok() { return true; diff --git a/src/cmd/cleanup.rs b/src/cmd/cleanup.rs index fca77c7..ee26241 100644 --- a/src/cmd/cleanup.rs +++ b/src/cmd/cleanup.rs @@ -83,7 +83,6 @@ fn running_apps(path: &Path) -> Vec { let mut proc_names = system .processes() .values() - .into_iter() .filter_map(|p| match p.exe().starts_with(path) { false => None, true => Some(p.name().to_owned()), diff --git a/src/cmd/info.rs b/src/cmd/info.rs index 92f252d..d29d481 100644 --- a/src/cmd/info.rs +++ b/src/cmd/info.rs @@ -40,7 +40,7 @@ pub fn cmd_info(matches: &ArgMatches, session: &Session) -> Result<()> { ); if idx != (length - 1) { - println!(""); + println!(); } } } diff --git a/src/cmd/install.rs b/src/cmd/install.rs index 816654d..65ed65d 100644 --- a/src/cmd/install.rs +++ b/src/cmd/install.rs @@ -42,8 +42,7 @@ pub fn cmd_install(matches: &ArgMatches, session: &Session) -> Result<()> { let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); let parsed = input.trim().parse::(); - if parsed.is_ok() { - index = parsed.unwrap(); + if let Ok(index) = parsed { if index < pkgs.len() { break; }