From c17c43af7cd5402cf00da0c05defd07bd804bb23 Mon Sep 17 00:00:00 2001 From: null8626 Date: Mon, 23 Sep 2024 18:13:25 +0700 Subject: [PATCH] refactor: let clippy do its job --- src/api/app/actions/build/bootstrap.rs | 4 ++-- src/api/app/actions/build/server_jar.rs | 4 ++-- src/api/app/actions/lockfile/mod.rs | 2 +- src/api/app/collect.rs | 2 +- src/api/app/http.rs | 4 ++-- src/api/app/step/cache_check.rs | 4 ++-- src/api/app/step/download.rs | 4 ++-- src/api/app/step/execute_java.rs | 7 +++---- src/api/app/step/mod.rs | 6 +++--- src/api/models/addon/addon_target.rs | 3 +-- src/api/models/launcher/mod.rs | 2 +- src/api/models/legacy/server_launcher.rs | 2 +- src/api/models/legacy/server_type.rs | 2 +- src/api/models/lockfile/mod.rs | 10 +--------- src/api/models/markdown/mod.rs | 2 +- src/api/models/modpack_source.rs | 2 +- src/api/models/mrpack/mod.rs | 2 +- src/api/models/packwiz/mod.rs | 2 +- src/api/models/server/mod.rs | 7 +++---- src/api/models/server/server_type.rs | 16 ++++++++-------- src/api/models/source.rs | 2 +- src/api/sources/buildtools/mod.rs | 2 +- src/api/sources/curseforge/mod.rs | 6 +++--- src/api/sources/modrinth/mod.rs | 4 ++-- src/api/sources/papermc/mod.rs | 2 +- src/api/sources/spigot/mod.rs | 4 ++-- src/api/sources/url/mod.rs | 2 +- src/api/sources/vanilla/version.rs | 6 +++--- src/api/tools/git/mod.rs | 2 +- src/api/tools/java/installation.rs | 2 +- src/api/tools/java/mod.rs | 4 ++-- src/api/utils/accessor.rs | 2 +- src/api/utils/hashing/curseforge.rs | 4 ++-- src/api/utils/hashing/mod.rs | 2 +- src/api/utils/markdown/mod.rs | 8 +++++++- src/api/utils/pathdiff.rs | 4 ++-- src/api/utils/toml.rs | 2 +- src/api/utils/zip.rs | 2 +- src/api/ws/mod.rs | 2 +- src/api/ws/msg.rs | 6 +++--- src/commands/init.rs | 8 ++------ src/commands/migrate.rs | 4 ++-- src/main.rs | 2 +- 43 files changed, 80 insertions(+), 89 deletions(-) diff --git a/src/api/app/actions/build/bootstrap.rs b/src/api/app/actions/build/bootstrap.rs index 59392ac..df5c21f 100644 --- a/src/api/app/actions/build/bootstrap.rs +++ b/src/api/app/actions/build/bootstrap.rs @@ -61,7 +61,7 @@ impl App { let x = input_base.clone(); futures::stream::iter(WalkDir::new(*input_base.clone())) - .map(|res| res.with_context({ || format!("Bootstrapping folder: {x:?}") })) + .map(|res| res.with_context(|| format!("Bootstrapping folder: {x:?}"))) .try_for_each_concurrent(Some(MAX_CONCURRENT_TASKS), move |entry| { let app = self.clone(); let output_base = output_base.clone(); @@ -75,7 +75,7 @@ impl App { &output_base, &input_base, entry.path(), - &changed_variables, + changed_variables, ) .await .with_context(|| format!("Bootstrapping file: {:?}", entry.path())) diff --git a/src/api/app/actions/build/server_jar.rs b/src/api/app/actions/build/server_jar.rs index ccfb0a4..16ea090 100644 --- a/src/api/app/actions/build/server_jar.rs +++ b/src/api/app/actions/build/server_jar.rs @@ -10,9 +10,9 @@ impl App { if let Some((_, server)) = &*self.server.read().await { println!("Installing server jar"); - let jar = server.get_jar(&self).await?; + let jar = server.get_jar(self).await?; - let steps = jar.resolve_steps(&self, Environment::Server).await?; + let steps = jar.resolve_steps(self, Environment::Server).await?; self.execute_steps(base, &steps).await?; } diff --git a/src/api/app/actions/lockfile/mod.rs b/src/api/app/actions/lockfile/mod.rs index f75fb3e..38c7613 100644 --- a/src/api/app/actions/lockfile/mod.rs +++ b/src/api/app/actions/lockfile/mod.rs @@ -41,7 +41,7 @@ impl App { Ok(()) } - /// Adds an addon to the new_lockfile + /// Adds an addon to the `new_lockfile` pub async fn add_addon_to_lockfile(self: Arc, addon: Addon) { self.new_lockfile.write().await.addons.push(addon); } diff --git a/src/api/app/collect.rs b/src/api/app/collect.rs index 44288bb..b8c0223 100644 --- a/src/api/app/collect.rs +++ b/src/api/app/collect.rs @@ -44,7 +44,7 @@ impl App { let mut addons = vec![]; for (relative_to, source) in self.collect_sources().await? { - addons.extend_from_slice(&source.resolve_addons(&self, &relative_to).await?); + addons.extend_from_slice(&source.resolve_addons(self, &relative_to).await?); } Ok(addons) diff --git a/src/api/app/http.rs b/src/api/app/http.rs index 581726c..abf77c9 100644 --- a/src/api/app/http.rs +++ b/src/api/app/http.rs @@ -69,7 +69,7 @@ impl App { let full = res.bytes().await?; - Ok(serde_json::from_slice(&full) - .with_context(|| format!("JSON parsing error: {}", String::from_utf8_lossy(&full)))?) + serde_json::from_slice(&full) + .with_context(|| format!("JSON parsing error: {}", String::from_utf8_lossy(&full))) } } diff --git a/src/api/app/step/cache_check.rs b/src/api/app/step/cache_check.rs index 0c96b96..0a9bced 100644 --- a/src/api/app/step/cache_check.rs +++ b/src/api/app/step/cache_check.rs @@ -76,7 +76,7 @@ impl App { hasher.update(&item); } - let hash = hex::encode(&hasher.finalize()); + let hash = hex::encode(hasher.finalize()); if content == hash { // size and hash match, skip rest of the steps @@ -146,7 +146,7 @@ impl App { } if let Some((_, hasher, content)) = hasher { - let hash = hex::encode(&hasher.finalize()); + let hash = hex::encode(hasher.finalize()); if hash != content { // TODO: print warning diff --git a/src/api/app/step/download.rs b/src/api/app/step/download.rs index 13b0125..2ac5510 100644 --- a/src/api/app/step/download.rs +++ b/src/api/app/step/download.rs @@ -40,7 +40,7 @@ impl App { let target_destination = cache_destination.as_ref().unwrap_or(&output_destination); - create_parents(&target_destination).await?; + create_parents(target_destination).await?; let target_file = tokio::fs::File::create(&target_destination) .await .with_context(|| format!("Creating file: {}", target_destination.display()))?; @@ -55,7 +55,7 @@ impl App { } if let Some((_, hasher, content)) = hasher { - let hash = hex::encode(&hasher.finalize()); + let hash = hex::encode(hasher.finalize()); if hash != content { bail!("Mismatched hash!"); diff --git a/src/api/app/step/execute_java.rs b/src/api/app/step/execute_java.rs index e39cfde..4a61ac2 100644 --- a/src/api/app/step/execute_java.rs +++ b/src/api/app/step/execute_java.rs @@ -23,11 +23,11 @@ impl App { let java = tools::java::get_java_installations() .await - .into_iter() + .iter() .find(|j| j.version >= version.unwrap_or_default()) .ok_or(anyhow!( "Java with version {} or higher not found, cannot proceed", - version.map(|v| v.to_string()).unwrap_or("any".to_owned()) + version.map_or("any".to_owned(), |v| v.to_string()) ))?; let mut proc = JavaProcess::new(&dir.canonicalize()?, &java.path, args)?; @@ -44,8 +44,7 @@ impl App { bail!( "Java process exited with code {}", res.code() - .map(|x| x.to_string()) - .unwrap_or("unknown".to_owned()) + .map_or("unknown".to_owned(), |x| x.to_string()) ); } diff --git a/src/api/app/step/mod.rs b/src/api/app/step/mod.rs index 9997a8d..c451c1c 100644 --- a/src/api/app/step/mod.rs +++ b/src/api/app/step/mod.rs @@ -12,8 +12,8 @@ mod remove_file; use super::App; impl App { - /// Execute a list of steps, taking care of their StepResult's. - /// Skips the next step when a step returns StepResult::Skip + /// Execute a list of steps, taking care of their `StepResult`'s. + /// Skips the next step when a step returns `StepResult::Skip` pub async fn execute_steps(&self, dir: &Path, steps: &[Step]) -> Result<()> { let mut iter = steps.iter(); @@ -43,7 +43,7 @@ impl App { .await .with_context(|| format!("URL: {url}")) .with_context(|| format!("File: {metadata:?}")) - .with_context(|| format!("Downloading a file")), + .with_context(|| "Downloading a file".to_string()), Step::ExecuteJava { args, diff --git a/src/api/models/addon/addon_target.rs b/src/api/models/addon/addon_target.rs index c646e4d..5055d6c 100644 --- a/src/api/models/addon/addon_target.rs +++ b/src/api/models/addon/addon_target.rs @@ -37,8 +37,7 @@ impl AddonTarget { Self::from_str( &Path::new(path) .parent() - .map(|p| p.to_string_lossy().into_owned()) - .unwrap_or(".".to_owned()), + .map_or(".".to_owned(), |p| p.to_string_lossy().into_owned()), ) } diff --git a/src/api/models/launcher/mod.rs b/src/api/models/launcher/mod.rs index 5057975..0fb03bd 100644 --- a/src/api/models/launcher/mod.rs +++ b/src/api/models/launcher/mod.rs @@ -2,7 +2,7 @@ use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::{borrow::ToOwned, collections::HashMap, env}; -use crate::api::utils::serde::*; +use crate::api::utils::serde::is_default; mod preset_flags; pub use preset_flags::*; diff --git a/src/api/models/legacy/server_launcher.rs b/src/api/models/legacy/server_launcher.rs index 743f690..bbf4a97 100644 --- a/src/api/models/legacy/server_launcher.rs +++ b/src/api/models/legacy/server_launcher.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use serde::{Deserialize, Serialize}; -use crate::api::utils::serde::*; +use crate::api::utils::serde::is_default; #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default)] #[serde(rename_all = "lowercase")] diff --git a/src/api/models/legacy/server_type.rs b/src/api/models/legacy/server_type.rs index 481ff7a..a27ff8d 100644 --- a/src/api/models/legacy/server_type.rs +++ b/src/api/models/legacy/server_type.rs @@ -1,4 +1,4 @@ -use crate::api::utils::serde::*; +use crate::api::utils::serde::str_latest; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use super::LegacyDownloadable; diff --git a/src/api/models/lockfile/mod.rs b/src/api/models/lockfile/mod.rs index 19e3a25..95af217 100644 --- a/src/api/models/lockfile/mod.rs +++ b/src/api/models/lockfile/mod.rs @@ -9,21 +9,13 @@ use super::Addon; pub const LOCKFILE: &str = ".mcman.lock"; #[derive(Debug, Serialize, Deserialize)] +#[derive(Default)] pub struct Lockfile { pub vars: HashMap, pub addons: Vec, pub bootstrapped_files: HashMap, } -impl Default for Lockfile { - fn default() -> Self { - Self { - addons: vec![], - bootstrapped_files: HashMap::new(), - vars: HashMap::new(), - } - } -} pub enum LockfileMessage { BootstrapFile(PathBuf, BootstrappedFile), diff --git a/src/api/models/markdown/mod.rs b/src/api/models/markdown/mod.rs index 47dd4fc..dd69372 100644 --- a/src/api/models/markdown/mod.rs +++ b/src/api/models/markdown/mod.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -use crate::api::utils::serde::*; +use crate::api::utils::serde::{bool_true, is_default, is_true}; pub mod render; diff --git a/src/api/models/modpack_source.rs b/src/api/models/modpack_source.rs index 5907b97..86822dc 100644 --- a/src/api/models/modpack_source.rs +++ b/src/api/models/modpack_source.rs @@ -47,6 +47,6 @@ impl ModpackSource { Self::Remote { url } => url, }; - Ok(Accessor::from(str).with_context(|| "Creating Accessor")?) + Accessor::from(str).with_context(|| "Creating Accessor") } } diff --git a/src/api/models/mrpack/mod.rs b/src/api/models/mrpack/mod.rs index 102bcc2..96a9010 100644 --- a/src/api/models/mrpack/mod.rs +++ b/src/api/models/mrpack/mod.rs @@ -15,7 +15,7 @@ use super::{server::ServerJar, Addon, AddonTarget, AddonType}; pub async fn resolve_mrpack_serverjar(app: &App, mut accessor: Accessor) -> Result { let index: MRPackIndex = accessor.json(app, MRPACK_INDEX_FILE).await?; - Ok(ServerJar::try_from(index.dependencies.clone())?) + ServerJar::try_from(index.dependencies.clone()) } pub async fn resolve_mrpack_addons(app: &App, mut accessor: Accessor) -> Result> { diff --git a/src/api/models/packwiz/mod.rs b/src/api/models/packwiz/mod.rs index 50af2c4..1bb1fbd 100644 --- a/src/api/models/packwiz/mod.rs +++ b/src/api/models/packwiz/mod.rs @@ -16,7 +16,7 @@ use super::{server::ServerJar, Addon, AddonTarget}; pub async fn resolve_packwiz_serverjar(app: &App, mut accessor: Accessor) -> Result { let pack: PackwizPack = accessor.toml(app, PACK_TOML).await?; - Ok(ServerJar::try_from(pack.versions.clone())?) + ServerJar::try_from(pack.versions.clone()) } pub async fn resolve_packwiz_addons(app: &App, mut accessor: Accessor) -> Result> { diff --git a/src/api/models/server/mod.rs b/src/api/models/server/mod.rs index e8d736c..3869ba5 100644 --- a/src/api/models/server/mod.rs +++ b/src/api/models/server/mod.rs @@ -63,7 +63,7 @@ impl Default for Server { } impl Server { - /// Gets the ServerJar via `jar` OR `Source` where `type=modpack` + /// Gets the `ServerJar` via `jar` OR `Source` where `type=modpack` pub async fn get_jar(&self, app: &App) -> Result { let relative_to = app.server.read().await.as_ref().map(|(p, _)| p.clone()); @@ -86,8 +86,7 @@ impl Server { if let Some(v) = self.launcher.java_version { get_java_installation_for(v) .await - .map(|j| j.path.to_string_lossy().into_owned()) - .unwrap_or(String::from("java")) + .map_or(String::from("java"), |j| j.path.to_string_lossy().into_owned()) } else { String::from("java") } @@ -96,7 +95,7 @@ impl Server { pub fn get_execution_arguments(&self) -> Vec { self.jar .as_ref() - .map(|s| s.get_execution_arguments()) + .map(server_type::ServerJar::get_execution_arguments) .unwrap_or_default() } diff --git a/src/api/models/server/server_type.rs b/src/api/models/server/server_type.rs index 126d338..be09f05 100644 --- a/src/api/models/server/server_type.rs +++ b/src/api/models/server/server_type.rs @@ -5,7 +5,7 @@ use crate::api::{ models::{Addon, AddonTarget, AddonType, Environment}, sources::buildtools, step::Step, - utils::serde::*, + utils::serde::str_latest, }; use anyhow::{anyhow, Result}; use schemars::JsonSchema; @@ -52,36 +52,36 @@ impl TryFrom> for ServerJar { server_type = Some(ServerType::Fabric { loader: v, installer: String::from("latest"), - }) + }); } if let Some(v) = value.get("fabric-loader").cloned() { server_type = Some(ServerType::Fabric { loader: v, installer: String::from("latest"), - }) + }); } if let Some(v) = value.get("quilt").cloned() { server_type = Some(ServerType::Quilt { loader: v, installer: String::from("latest"), - }) + }); } if let Some(v) = value.get("quilt-loader").cloned() { server_type = Some(ServerType::Quilt { loader: v, installer: String::from("latest"), - }) + }); } if let Some(v) = value.get("forge").cloned() { - server_type = Some(ServerType::Forge { loader: v }) + server_type = Some(ServerType::Forge { loader: v }); } if let Some(v) = value.get("neoforge").cloned() { - server_type = Some(ServerType::NeoForge { loader: v }) + server_type = Some(ServerType::NeoForge { loader: v }); } Ok(ServerJar { @@ -162,7 +162,7 @@ impl ServerJar { ServerType::BuildTools { .. } | ServerType::PaperMC { .. } | ServerType::Purpur { .. } => ServerFlavor::Patched, - ServerType::Custom { flavor, .. } => flavor.clone(), + ServerType::Custom { flavor, .. } => *flavor, ServerType::Fabric { .. } | ServerType::Forge { .. } | ServerType::Quilt { .. } diff --git a/src/api/models/source.rs b/src/api/models/source.rs index e34c1af..78c9c5b 100644 --- a/src/api/models/source.rs +++ b/src/api/models/source.rs @@ -95,7 +95,7 @@ impl Source { pub fn modpack_type(&self) -> Option { match &self.source_type { - SourceType::Modpack { modpack_type, .. } => Some(modpack_type.clone()), + SourceType::Modpack { modpack_type, .. } => Some(*modpack_type), _ => None, } } diff --git a/src/api/sources/buildtools/mod.rs b/src/api/sources/buildtools/mod.rs index fadae0e..5ef3c05 100644 --- a/src/api/sources/buildtools/mod.rs +++ b/src/api/sources/buildtools/mod.rs @@ -61,7 +61,7 @@ pub async fn resolve_buildtools_jar(app: &App) -> Result<(String, FileMeta)> { .await } -/// Resolve steps for using BuildTools to compile a server jar +/// Resolve steps for using `BuildTools` to compile a server jar pub async fn resolve_compile_steps( _app: &App, jar_name: &str, diff --git a/src/api/sources/curseforge/mod.rs b/src/api/sources/curseforge/mod.rs index 3b203c4..cc9be85 100644 --- a/src/api/sources/curseforge/mod.rs +++ b/src/api/sources/curseforge/mod.rs @@ -109,9 +109,9 @@ pub fn convert_hashes(hashes: Vec) -> HashMap for CurseforgeHashAlgo { - fn into(self) -> HashFormat { - match self { +impl From for HashFormat { + fn from(val: CurseforgeHashAlgo) -> Self { + match val { CurseforgeHashAlgo::Sha1 => HashFormat::Sha1, CurseforgeHashAlgo::Md5 => HashFormat::Md5, } diff --git a/src/api/sources/modrinth/mod.rs b/src/api/sources/modrinth/mod.rs index 11bd951..c5349e3 100644 --- a/src/api/sources/modrinth/mod.rs +++ b/src/api/sources/modrinth/mod.rs @@ -40,7 +40,7 @@ impl<'a> ModrinthAPI<'a> { } pub async fn fetch_versions(&self, id: &str) -> Result> { - Ok(self.fetch_all_versions(id).await?) + self.fetch_all_versions(id).await } pub async fn fetch_version(&self, id: &str, version: &str) -> Result { @@ -60,7 +60,7 @@ impl<'a> ModrinthAPI<'a> { let path = "modrinth/ids.json"; let store = self.0.cache.try_get_json::>(path)?; - if let Some(id) = store.as_ref().map(|ids| ids.get(slug)).flatten() { + if let Some(id) = store.as_ref().and_then(|ids| ids.get(slug)) { return Ok(id.to_owned()); } diff --git a/src/api/sources/papermc/mod.rs b/src/api/sources/papermc/mod.rs index b403be0..110fe3f 100644 --- a/src/api/sources/papermc/mod.rs +++ b/src/api/sources/papermc/mod.rs @@ -68,7 +68,7 @@ impl<'a> PaperMCAPI<'a> { version: &str, build: &str, ) -> Result> { - let resolved_build = self.fetch_build(project, &version, build).await?; + let resolved_build = self.fetch_build(project, version, build).await?; let download = resolved_build.downloads.get("application") .ok_or(anyhow!("downloads['application'] missing for papermc project {project} {version}, build {build} ({})", resolved_build.build))?; diff --git a/src/api/sources/spigot/mod.rs b/src/api/sources/spigot/mod.rs index 59048c4..5973373 100644 --- a/src/api/sources/spigot/mod.rs +++ b/src/api/sources/spigot/mod.rs @@ -23,10 +23,10 @@ pub struct SpigotAPI<'a>(pub &'a App); impl<'a> SpigotAPI<'a> { pub async fn fetch_api(&self, url: &str) -> Result { - Ok(self + self .0 .http_get_json(format!("{}/{url}", self.0.options.api_urls.spiget)) - .await?) + .await } pub async fn fetch_resource(&self, id: &str) -> Result { diff --git a/src/api/sources/url/mod.rs b/src/api/sources/url/mod.rs index 55a75bc..d831ec5 100644 --- a/src/api/sources/url/mod.rs +++ b/src/api/sources/url/mod.rs @@ -22,7 +22,7 @@ pub async fn resolve_steps_for_url( }; Ok(vec![Step::Download { - url: url.into(), + url, metadata, }]) } diff --git a/src/api/sources/vanilla/version.rs b/src/api/sources/vanilla/version.rs index 47ba0e7..07ca9c6 100644 --- a/src/api/sources/vanilla/version.rs +++ b/src/api/sources/vanilla/version.rs @@ -146,7 +146,7 @@ pub struct PistonLibraryDownload { pub artifact: PistonFile, /// Conditional files that may be needed to be downloaded alongside the library - /// The HashMap key specifies a classifier as additional information for downloading files + /// The `HashMap` key specifies a classifier as additional information for downloading files pub classifiers: Option>, } @@ -174,9 +174,9 @@ pub struct PistonFile { pub size: u64, pub url: String, - /// (AssetIndex only) The game version ID the assets are for + /// (`AssetIndex` only) The game version ID the assets are for pub id: Option, - /// (AssetIndex only) The size of the game version's assets + /// (`AssetIndex` only) The size of the game version's assets pub total_size: Option, /// Only present on library files diff --git a/src/api/tools/git/mod.rs b/src/api/tools/git/mod.rs index 031a838..c0f18d9 100644 --- a/src/api/tools/git/mod.rs +++ b/src/api/tools/git/mod.rs @@ -4,7 +4,7 @@ use anyhow::{anyhow, Result}; pub const GIT: &str = "git"; -static GIT_VERSION: LazyLock> = LazyLock::new(|| version_check()); +static GIT_VERSION: LazyLock> = LazyLock::new(version_check); pub fn require_git() -> Result<()> { GIT_VERSION diff --git a/src/api/tools/java/installation.rs b/src/api/tools/java/installation.rs index 0c6ae96..7f944d3 100644 --- a/src/api/tools/java/installation.rs +++ b/src/api/tools/java/installation.rs @@ -47,7 +47,7 @@ pub async fn get_java_installations() -> &'static Vec { pub async fn get_java_installation_for(ver: JavaVersion) -> Option { get_java_installations() .await - .into_iter() + .iter() .find(|v| v.version == ver) .cloned() } diff --git a/src/api/tools/java/mod.rs b/src/api/tools/java/mod.rs index 2317e8f..8d73454 100644 --- a/src/api/tools/java/mod.rs +++ b/src/api/tools/java/mod.rs @@ -54,14 +54,14 @@ impl JavaProcess { .stdout(Stdio::piped()) .stdin(Stdio::piped()) .spawn() - .with_context(|| format!("Spawning java process"))?; + .with_context(|| "Spawning java process".to_string())?; log::info!("Child process spawned"); Ok(Self { child }) } - pub fn lines(&mut self, f: F) -> () + pub fn lines(&mut self, f: F) where F: Fn(&str) + Send + 'static, { diff --git a/src/api/utils/accessor.rs b/src/api/utils/accessor.rs index c630813..92b6a6a 100644 --- a/src/api/utils/accessor.rs +++ b/src/api/utils/accessor.rs @@ -45,7 +45,7 @@ impl Accessor { Accessor::ZipLocal((_, zip)) => Ok(zip.file_names().map(ToOwned::to_owned).collect()), Accessor::Local(path) => Ok(path .read_dir()? - .filter_map(|r| r.ok()) + .filter_map(std::result::Result::ok) .map(|n| n.file_name().to_string_lossy().into_owned()) .collect()), Accessor::Remote(_) => Err(anyhow!("cannot dir() Accessor::Remote")), diff --git a/src/api/utils/hashing/curseforge.rs b/src/api/utils/hashing/curseforge.rs index 9ea8451..09681fb 100644 --- a/src/api/utils/hashing/curseforge.rs +++ b/src/api/utils/hashing/curseforge.rs @@ -15,13 +15,13 @@ impl Update for CurseforgeHasher { data.iter() .copied() .filter(|&e| e != 9 && e != 10 && e != 13 && e != 32), - ) + ); } } impl Reset for CurseforgeHasher { fn reset(&mut self) { - self.0 = Vec::new() + self.0 = Vec::new(); } } diff --git a/src/api/utils/hashing/mod.rs b/src/api/utils/hashing/mod.rs index 0329cba..102701b 100644 --- a/src/api/utils/hashing/mod.rs +++ b/src/api/utils/hashing/mod.rs @@ -55,5 +55,5 @@ pub fn get_best_hash(hashes: &HashMap) -> Option<(HashFormat .or(hashes.get_key_value(&HashFormat::Md5)) .or(hashes.get_key_value(&HashFormat::Sha1)) .or(hashes.get_key_value(&HashFormat::Curseforge)) - .map(|(k, v)| (k.clone(), v.clone())) + .map(|(k, v)| (*k, v.clone())) } diff --git a/src/api/utils/markdown/mod.rs b/src/api/utils/markdown/mod.rs index 21d7914..264b314 100644 --- a/src/api/utils/markdown/mod.rs +++ b/src/api/utils/markdown/mod.rs @@ -69,6 +69,12 @@ pub struct MarkdownTable { pub rows: Vec>, } +impl Default for MarkdownTable { + fn default() -> Self { + Self::new() + } +} + impl MarkdownTable { pub fn new() -> Self { Self { @@ -96,7 +102,7 @@ impl MarkdownTable { } fn join(li: impl Iterator) -> String { - li.collect::>().join("") + li.collect::() } let header = wrap( diff --git a/src/api/utils/pathdiff.rs b/src/api/utils/pathdiff.rs index 9558c5f..e2cbf55 100644 --- a/src/api/utils/pathdiff.rs +++ b/src/api/utils/pathdiff.rs @@ -1,6 +1,6 @@ -//! https://github.com/Manishearth/pathdiff +//! -use std::path::*; +use std::path::{Component, Path, PathBuf}; use anyhow::{anyhow, Result}; diff --git a/src/api/utils/toml.rs b/src/api/utils/toml.rs index 1778ba5..ccceb18 100644 --- a/src/api/utils/toml.rs +++ b/src/api/utils/toml.rs @@ -27,7 +27,7 @@ pub fn try_find_toml_upwards(filename: &str) -> Result(path: &Path) -> Result { - let data: T = toml::from_str(&std::fs::read_to_string(&path)?)?; + let data: T = toml::from_str(&std::fs::read_to_string(path)?)?; Ok(data) } diff --git a/src/api/utils/zip.rs b/src/api/utils/zip.rs index 6ed41b9..5842d43 100644 --- a/src/api/utils/zip.rs +++ b/src/api/utils/zip.rs @@ -25,7 +25,7 @@ pub async fn unzip(reader: T, to: &Path, prefix: Option) files = files .into_iter() .map(|f| f.replacen(&prefix, "", 1)) - .collect() + .collect(); } } diff --git a/src/api/ws/mod.rs b/src/api/ws/mod.rs index 57b58c1..87668ca 100644 --- a/src/api/ws/mod.rs +++ b/src/api/ws/mod.rs @@ -1,4 +1,4 @@ -//! WebSocket Server implementation for third party editors +//! `WebSocket` Server implementation for third party editors use std::sync::Arc; diff --git a/src/api/ws/msg.rs b/src/api/ws/msg.rs index 905800d..8864a8c 100644 --- a/src/api/ws/msg.rs +++ b/src/api/ws/msg.rs @@ -29,8 +29,8 @@ pub enum MsgOut { }, } -impl Into for MsgOut { - fn into(self) -> Message { - Message::text(serde_json::to_string(&self).unwrap()) +impl From for Message { + fn from(val: MsgOut) -> Self { + Message::text(serde_json::to_string(&val).unwrap()) } } diff --git a/src/commands/init.rs b/src/commands/init.rs index 6708865..90ea504 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -54,9 +54,7 @@ pub async fn init_server(app: Arc, args: Args) -> Result<()> { } let name: String = args - .name - .map(Ok) - .unwrap_or_else(|| cliclack::input("Name of the server?").interact())?; + .name.map_or_else(|| cliclack::input("Name of the server?").interact(), Ok)?; let mut server = Server { name, @@ -82,9 +80,7 @@ pub async fn action_init_network(app: Arc, args: Args) -> Result<()> { let path = dir.join(NETWORK_TOML); let name: String = args - .name - .map(Ok) - .unwrap_or_else(|| cliclack::input("Name of the network?").interact())?; + .name.map_or_else(|| cliclack::input("Name of the network?").interact(), Ok)?; let mut nw = Network { name, diff --git a/src/commands/migrate.rs b/src/commands/migrate.rs index cad2e30..b0c4de4 100644 --- a/src/commands/migrate.rs +++ b/src/commands/migrate.rs @@ -102,7 +102,7 @@ pub async fn migrate_server() -> Result<()> { }; write_toml(&std::env::current_dir()?, "addons.toml", &file) - .with_context(|| format!("Writing addons.toml"))?; + .with_context(|| "Writing addons.toml".to_string())?; let source = Source { source_type: SourceType::File { @@ -173,7 +173,7 @@ pub async fn migrate_server() -> Result<()> { std::fs::copy("./server.toml", "./__v1__server.toml")?; write_toml(&std::env::current_dir()?, "server.toml", &server) - .with_context(|| format!("Writing server.toml"))?; + .with_context(|| "Writing server.toml".to_string())?; println!("Migrated! You may now delete the backup file if there are no issues."); diff --git a/src/main.rs b/src/main.rs index 34a63da..70576ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,7 @@ async fn main() -> Result<()> { let mut wg = app.server.write().await; // if no server.toml etc and is inside a packwiz folder if wg.is_none() { - let (_, server) = wg.get_or_insert_with(|| (base.into(), Server::default())); + let (_, server) = wg.get_or_insert_with(|| (base, Server::default())); server.sources.push(Source { source_type: SourceType::Modpack { modpack_source: ModpackSource::Local {