From 6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 11:12:04 +0200 Subject: do nearly anything to shut clippy up --- src/lib.rs | 52 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index c51381c..750580f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ use std::{ use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; pub use apis::*; pub use commands::*; -use error::{ErrorType, MLError, MLE}; +use error::{EType, MLErr, MLE}; use indicatif::{ProgressBar, ProgressStyle}; use serde::{Deserialize, Serialize}; @@ -39,13 +39,15 @@ pub enum Modloader { } impl Modloader { + /// # Errors + /// # Panics pub fn from(string: &str) -> MLE { match string { "forge" => Ok(Modloader::Forge), "fabric" => Ok(Modloader::Fabric), "quilt" => Ok(Modloader::Quilt), _ => { - Err(MLError::new(ErrorType::ArgumentError, "UNKNOWN_MODLOADER")) + Err(MLErr::new(EType::ArgumentError, "UNKNOWN_MODLOADER")) } } } @@ -72,14 +74,18 @@ pub enum VersionLevel { /// Checks if update needed (time) /// if yes: get versions, update +/// # Errors +/// # Panics pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { let p = ProgressBar::new(1); - p.set_style(ProgressStyle::with_template(STYLE_MESSAGE).unwrap()); + p.set_style(ProgressStyle::with_template(STYLE_MESSAGE).map_err(|_| { + MLErr::new(EType::LibIndicatif, "template error") + })?); p.set_message("Update minecraft versions"); let creation_time = fs::metadata(path)?.created()?; if !force - && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) + && creation_time.elapsed().map_err(|_| MLErr::new(EType::LibIndicatif, "SystemTimeError"))? < Duration::from_secs(60 * 60 * 24) { return Ok(()); } @@ -94,6 +100,7 @@ pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { } /// Loads game versions from file +/// # Errors pub fn load_game_versions(path: &str) -> MLE> { let mut file = File::open(path)?; let mut data = String::new(); @@ -103,7 +110,8 @@ pub fn load_game_versions(path: &str) -> MLE> { } impl VersionLevel { - #[must_use] pub fn from(str: &str) -> Self { + #[must_use] + pub fn from(str: &str) -> Self { match str { "release" => VersionLevel::Release, "snapshot" => VersionLevel::Snapshot, @@ -111,6 +119,12 @@ impl VersionLevel { } } + /// . + /// + /// # Panics + /// + /// Panics if . + /// # Errors pub async fn get( self, versions_path: &str, @@ -122,23 +136,35 @@ impl VersionLevel { match self { VersionLevel::Release => { - let release = versions + if let Some(release) = versions .find(|ver| ver.version_type == GameVersionType::release) - .unwrap(); - Ok(release.version) + { + Ok(release.version) + } else { + Err(MLErr::new( + EType::Other, + "no minecraft release version found", + )) + } } VersionLevel::Snapshot => { - let snapshot = versions + if let Some(snapshot) = versions .find(|ver| ver.version_type == GameVersionType::snapshot) - .unwrap(); - Ok(snapshot.version) + { + Ok(snapshot.version) + } else { + Err(MLErr::new( + EType::Other, + "no minecraft snapshot version found", + )) + } } VersionLevel::Version(v) => { if versions.any(|ver| ver.version == v) { Ok(v) } else { - Err(MLError::new( - ErrorType::ConfigError, + Err(MLErr::new( + EType::ConfigError, "unknown minecraft version", )) } -- cgit v1.2.3