diff --git a/src/cli/build.rs b/src/cli/build.rs index 04193ed..30b1715 100644 --- a/src/cli/build.rs +++ b/src/cli/build.rs @@ -14,8 +14,8 @@ pub fn cmd() -> Command { pub fn run(matches: &ArgMatches) -> ExitCode { let debug_mode: Option = matches .get_flag("build-debug") - .then(|| true) - .or(matches.get_flag("build-release").then(|| false)); + .then_some(true) + .or(matches.get_flag("build-release").then_some(false)); let now = Instant::now(); let mut project = match Project::current() { Ok(p) => p, diff --git a/src/cli/completions.rs b/src/cli/completions.rs index f1f6b8c..9be774a 100644 --- a/src/cli/completions.rs +++ b/src/cli/completions.rs @@ -1,4 +1,4 @@ -use clap::{Arg, ArgAction, ArgMatches, Command}; +use clap::{Arg, ArgMatches, Command}; use clap_complete::Shell; use std::{io, process::ExitCode}; diff --git a/src/cli/explain.rs b/src/cli/explain.rs index 100e317..f7ae8c4 100644 --- a/src/cli/explain.rs +++ b/src/cli/explain.rs @@ -12,7 +12,7 @@ pub fn run(matches: &ArgMatches) -> ExitCode { let id: &String = matches.get_one("id").unwrap(); let code: u8 = id .parse() - .expect(format!("Code is invalid (must be 0-255)",).as_str()); + .unwrap_or_else(|_| { panic!("{}", "Code is invalid (must be 0-255)".to_string()) }); let notif = match diagnostic::Notification::from_code(code) { Some(n) => n, None => { diff --git a/src/cli/sync.rs b/src/cli/sync.rs index 49cf471..b331d8c 100644 --- a/src/cli/sync.rs +++ b/src/cli/sync.rs @@ -8,9 +8,9 @@ use std::fs; use std::str::FromStr; use std::{env, path::PathBuf, process::ExitCode}; -const DEV_BP: &'static str = "development_behavior_packs"; -const DEV_RP: &'static str = "development_resource_packs"; -const DEV_SP: &'static str = "development_skin_packs"; +const DEV_BP: &str = "development_behavior_packs"; +const DEV_RP: &str = "development_resource_packs"; +const DEV_SP: &str = "development_skin_packs"; mod location { use crate::diagnostic; diff --git a/src/cli/uuid/refresh.rs b/src/cli/uuid/refresh.rs index dbfdd8e..8cf38db 100644 --- a/src/cli/uuid/refresh.rs +++ b/src/cli/uuid/refresh.rs @@ -58,11 +58,11 @@ fn update(uuids: &mut Uuids, packs: Vec, kinds: Vec, uuid: Option< .into_iter() .filter(|i| packs.contains(&i.1)) { - if kinds.contains(&&"header".to_string()) { + if kinds.contains(&"header".to_string()) { data.0.update_header(uuid.copied()); log::info!("Refreshed header UUID for {}", data.1); } - if kinds.contains(&&"module".to_string()) { + if kinds.contains(&"module".to_string()) { data.0.update_module(uuid.copied()); log::info!("Refreshed module UUID for {}", data.1); } diff --git a/src/cli/watch.rs b/src/cli/watch.rs index 7e37276..2dd007e 100644 --- a/src/cli/watch.rs +++ b/src/cli/watch.rs @@ -97,7 +97,7 @@ where // ignored by gitignore. So we handle this case by including such files into the watched paths list. let any_external_paths = paths .iter() - .filter(|p| !p.starts_with(&paths::root())) + .filter(|p| !p.starts_with(paths::root())) .cloned(); let mut paths = remove_ignored_files(&paths::root(), &paths[..]); paths.extend(any_external_paths); diff --git a/src/filter.rs b/src/filter.rs index 7ab0383..46951a1 100644 --- a/src/filter.rs +++ b/src/filter.rs @@ -8,7 +8,7 @@ pub fn evaluate(source: &str) -> Result> { .register_fn("dll_prefix", || DLL_PREFIX) .register_fn("dll_suffix", || DLL_SUFFIX) .register_fn("env", |key: rhai::ImmutableString| { - env::var(key.as_str()).unwrap_or(String::new()) + env::var(key.as_str()).unwrap_or_default() }) .register_fn("env_present", |key: rhai::ImmutableString| { env::var(key.as_str()).is_err_and(|e| e == env::VarError::NotPresent) diff --git a/src/health.rs b/src/health.rs index aa99a8a..676d147 100644 --- a/src/health.rs +++ b/src/health.rs @@ -54,7 +54,7 @@ impl Health { let uuids = self.root.join(paths::uuids()); let valid_file_format: bool = (|| { toml::from_str::(match fs::read_to_string(&uuids) { - Ok(ref data) => &data, + Ok(ref data) => data, Err(e) => { log::error!("Failed to read UUID file: {}", e); return false; @@ -95,7 +95,7 @@ impl Health { match data { Err(e) => { log::error!("Invalid TOML: {}", e); - return false; + false } Ok(mut data) => { let mut modified = false; diff --git a/src/localization.rs b/src/localization.rs index 3211e8e..274bce4 100644 --- a/src/localization.rs +++ b/src/localization.rs @@ -8,7 +8,7 @@ use std::io::Write; use std::path::PathBuf; /// File extension for Minecraft language files. -pub const LANGUAGE_FILE_EXTENSION: &'static str = "lang"; +pub const LANGUAGE_FILE_EXTENSION: &str = "lang"; /// A value mapped to languages. pub type Localized = HashMap; @@ -71,12 +71,7 @@ impl Default for LanguageGroups { impl LanguageGroups { /// Returns the language group which contains `language`. pub fn group_of(&self, language: &Language) -> Option<&LanguageGroup> { - for group in &self.0 { - if group.contains(language) { - return Some(group); - } - } - None + self.0.iter().find(|&group| group.contains(language)) } /// Adds a language to it's own group if it is not present in any group yet. @@ -158,7 +153,7 @@ impl LanguageGroups { // Step 2 for lang in given { - match self.group_of(&lang) { + match self.group_of(lang) { Some(group) if self.group_of(target).is_some_and(|g| g == group) => { return Some(lang); } @@ -173,7 +168,7 @@ impl LanguageGroups { // Step 4 for lang in given { - match self.group_of(&lang) { + match self.group_of(lang) { Some(group) if self.group_of(fallback).is_some_and(|g| g == group) => { return Some(lang); } @@ -200,7 +195,7 @@ pub fn generate_language_json(dir: &PathBuf) -> Result<(), Box match stem.to_str() { Some(stem) => { if Language::from_file_id(stem).is_some() { @@ -222,7 +217,6 @@ pub fn generate_language_json(dir: &PathBuf) -> Result<(), Box = Vec::new(); for (lang, translation) in target { - append_language_file(dir, &lang, &key, &translation)?; - covered.push(&lang); + append_language_file(dir, lang, key, translation)?; + covered.push(lang); } // cover all remaining languages with their fallback if present @@ -257,14 +251,9 @@ pub fn update_language_files( for remaining in remaining_languages { if let Some(lang_with_translation) = groups.best_language(remaining, &covered, fallback) { - let translation = target.get(lang_with_translation).expect( - format!( - "{} should provide a translation for {}", - lang_with_translation, key - ) - .as_str(), - ); - append_language_file(dir, remaining, &key, &translation)?; + let translation = target.get(lang_with_translation).unwrap_or_else(|| panic!("{} should provide a translation for {}", + lang_with_translation, key)); + append_language_file(dir, remaining, key, translation)?; } else { // TODO: this is probably unreachable as `name` and `description` are always at least set // to some language @@ -568,8 +557,8 @@ impl Language { L::Other(id, _name) => { let pair = id .split_once('-') - .expect(format!("language has invalid id: {}", id).as_str()); - vec![pair.0, "_", pair.1.to_uppercase().as_str()].join("") + .unwrap_or_else(|| panic!("language has invalid id: {}", id)); + [pair.0, "_", pair.1.to_uppercase().as_str()].join("") } } } diff --git a/src/paths.rs b/src/paths.rs index 202cb63..dfbdfd2 100644 --- a/src/paths.rs +++ b/src/paths.rs @@ -2,7 +2,7 @@ use std::env::current_dir; use std::path::PathBuf; /// The name of the file which contains the ID of the Allay project. -pub const FINGERPRINT: &'static str = ".allay-fingerprint"; +pub const FINGERPRINT: &str = ".allay-fingerprint"; /// Returns the path of the project root or [`None`] if an `allay.toml` file cannot be found. pub fn try_root() -> Option { diff --git a/src/project.rs b/src/project.rs index 8bde7f7..a59c060 100644 --- a/src/project.rs +++ b/src/project.rs @@ -143,7 +143,7 @@ impl Project { )?; log::debug!("Adding fingerprint"); - if let Err(e) = fs::write(&dest.join(paths::FINGERPRINT), self.id) { + if let Err(e) = fs::write(dest.join(paths::FINGERPRINT), self.id) { log::error!("Failed to add fingerprint: {}", e); }; diff --git a/src/scaffolding/mod.rs b/src/scaffolding/mod.rs index 7e14461..24c1931 100644 --- a/src/scaffolding/mod.rs +++ b/src/scaffolding/mod.rs @@ -1,11 +1,11 @@ //! Project skeleton for an Allay project. /// The gitignore template. -pub const GITIGNORE: &'static [u8] = include_bytes!("gitignore"); +pub const GITIGNORE: &[u8] = include_bytes!("gitignore"); /// The configuration file (allay.toml) template. // TODO: use template engine to fill in info like git username in authors field -pub const CONFIG: &'static [u8] = include_bytes!("allay.toml"); +pub const CONFIG: &[u8] = include_bytes!("allay.toml"); /// The default pack icon. -pub const PACK_ICON: &'static [u8] = include_bytes!("pack_icon.png"); +pub const PACK_ICON: &[u8] = include_bytes!("pack_icon.png"); diff --git a/src/uuid.rs b/src/uuid.rs index 0369ba6..13934d5 100644 --- a/src/uuid.rs +++ b/src/uuid.rs @@ -75,15 +75,15 @@ pub struct Uuids { pub wt: Data, } -impl Into for Uuids { - fn into(self) -> Table { +impl From for Table { + fn from(val: Uuids) -> Self { let mut table = Table::new(); table.add_row(row![b => "", "Header", "Module", "Dependencies"]); for (name, pack) in [ - ("BP", self.bp), - ("RP", self.rp), - ("SP", self.sp), - ("WT", self.wt), + ("BP", val.bp), + ("RP", val.rp), + ("SP", val.sp), + ("WT", val.wt), ] { table.add_row(row![ name,