diff --git a/src/api/items.rs b/src/api/items.rs index 411df08..9c62989 100644 --- a/src/api/items.rs +++ b/src/api/items.rs @@ -33,10 +33,6 @@ impl Items { /// Returns the items indexed by ID pub fn items(&self) -> DataResult> { - Ok(self - .items_array()? - .into_iter() - .map(|i| (i.id.clone(), i)) - .collect()) + Ok(self.items_array()?.into_iter().map(|i| (i.id, i)).collect()) } } diff --git a/src/api/versions.rs b/src/api/versions.rs index 516ce10..4a1fe57 100644 --- a/src/api/versions.rs +++ b/src/api/versions.rs @@ -29,7 +29,7 @@ pub fn latest_stable() -> DataResult { .into_iter() .filter_map(|v| { let version_string = v.clone(); - let mut parts = version_string.split("."); + let mut parts = version_string.split('.'); Some(( v, diff --git a/src/data/mod.rs b/src/data/mod.rs index fa6730c..c5dfa08 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -41,9 +41,9 @@ pub static VERSIONS_FILE: &str = "versions"; pub fn get_common_file(filename: &str) -> DataResult { MINECRAFT_DATA .get_file(format!("pc/common/{}.json", filename)) - .ok_or(DataError::NotFoundError(filename.to_string()))? + .ok_or_else(|| DataError::NotFoundError(filename.to_string()))? .contents_utf8() - .ok_or(DataError::InvalidEncodingError(filename.to_string())) + .ok_or_else(|| DataError::InvalidEncodingError(filename.to_string())) .map(|d| d.to_string()) } @@ -52,12 +52,11 @@ pub fn get_version_specific_file(version: &Version, filename: &str) -> DataResul let path = get_path(version, filename)?; MINECRAFT_DATA .get_file(format!("{}/{}.json", path, filename)) - .ok_or(DataError::NotFoundError(format!( - "{}/{}", - version.minecraft_version, filename - )))? + .ok_or_else(|| { + DataError::NotFoundError(format!("{}/{}", version.minecraft_version, filename)) + })? .contents_utf8() - .ok_or(DataError::InvalidEncodingError(filename.to_string())) + .ok_or_else(|| DataError::InvalidEncodingError(filename.to_string())) .map(|d| d.to_string()) } @@ -69,20 +68,18 @@ pub fn get_path(version: &Version, filename: &str) -> DataResult { PATHS .pc .get(&version.minecraft_version) - .ok_or(DataError::NotFoundError(version.minecraft_version.clone()))? + .ok_or_else(|| DataError::NotFoundError(version.minecraft_version.clone()))? .get(filename) .cloned() - .ok_or(DataError::NotFoundError(filename.to_string())) + .ok_or_else(|| DataError::NotFoundError(filename.to_string())) } /// Returns the parsed data paths fn get_datapaths() -> DataResult { let content = MINECRAFT_DATA .get_file("dataPaths.json") - .ok_or(DataError::NotFoundError("dataPaths.json".to_string()))? + .ok_or_else(|| DataError::NotFoundError("dataPaths.json".to_string()))? .contents_utf8() - .ok_or(DataError::InvalidEncodingError( - "dataPaths.json".to_string(), - ))?; + .ok_or_else(|| DataError::InvalidEncodingError("dataPaths.json".to_string()))?; serde_json::from_str::(content).map_err(DataError::from) }