Fix style issues

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/9/head
trivernis 2 years ago
parent fd218f5419
commit 0b32ffbf30
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -33,10 +33,6 @@ impl Items {
/// Returns the items indexed by ID /// Returns the items indexed by ID
pub fn items(&self) -> DataResult<HashMap<u32, Item>> { pub fn items(&self) -> DataResult<HashMap<u32, Item>> {
Ok(self Ok(self.items_array()?.into_iter().map(|i| (i.id, i)).collect())
.items_array()?
.into_iter()
.map(|i| (i.id.clone(), i))
.collect())
} }
} }

@ -29,7 +29,7 @@ pub fn latest_stable() -> DataResult<Version> {
.into_iter() .into_iter()
.filter_map(|v| { .filter_map(|v| {
let version_string = v.clone(); let version_string = v.clone();
let mut parts = version_string.split("."); let mut parts = version_string.split('.');
Some(( Some((
v, v,

@ -41,9 +41,9 @@ pub static VERSIONS_FILE: &str = "versions";
pub fn get_common_file(filename: &str) -> DataResult<String> { pub fn get_common_file(filename: &str) -> DataResult<String> {
MINECRAFT_DATA MINECRAFT_DATA
.get_file(format!("pc/common/{}.json", filename)) .get_file(format!("pc/common/{}.json", filename))
.ok_or(DataError::NotFoundError(filename.to_string()))? .ok_or_else(|| DataError::NotFoundError(filename.to_string()))?
.contents_utf8() .contents_utf8()
.ok_or(DataError::InvalidEncodingError(filename.to_string())) .ok_or_else(|| DataError::InvalidEncodingError(filename.to_string()))
.map(|d| d.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)?; let path = get_path(version, filename)?;
MINECRAFT_DATA MINECRAFT_DATA
.get_file(format!("{}/{}.json", path, filename)) .get_file(format!("{}/{}.json", path, filename))
.ok_or(DataError::NotFoundError(format!( .ok_or_else(|| {
"{}/{}", DataError::NotFoundError(format!("{}/{}", version.minecraft_version, filename))
version.minecraft_version, filename })?
)))?
.contents_utf8() .contents_utf8()
.ok_or(DataError::InvalidEncodingError(filename.to_string())) .ok_or_else(|| DataError::InvalidEncodingError(filename.to_string()))
.map(|d| d.to_string()) .map(|d| d.to_string())
} }
@ -69,20 +68,18 @@ pub fn get_path(version: &Version, filename: &str) -> DataResult<String> {
PATHS PATHS
.pc .pc
.get(&version.minecraft_version) .get(&version.minecraft_version)
.ok_or(DataError::NotFoundError(version.minecraft_version.clone()))? .ok_or_else(|| DataError::NotFoundError(version.minecraft_version.clone()))?
.get(filename) .get(filename)
.cloned() .cloned()
.ok_or(DataError::NotFoundError(filename.to_string())) .ok_or_else(|| DataError::NotFoundError(filename.to_string()))
} }
/// Returns the parsed data paths /// Returns the parsed data paths
fn get_datapaths() -> DataResult<Datapaths> { fn get_datapaths() -> DataResult<Datapaths> {
let content = MINECRAFT_DATA let content = MINECRAFT_DATA
.get_file("dataPaths.json") .get_file("dataPaths.json")
.ok_or(DataError::NotFoundError("dataPaths.json".to_string()))? .ok_or_else(|| DataError::NotFoundError("dataPaths.json".to_string()))?
.contents_utf8() .contents_utf8()
.ok_or(DataError::InvalidEncodingError( .ok_or_else(|| DataError::InvalidEncodingError("dataPaths.json".to_string()))?;
"dataPaths.json".to_string(),
))?;
serde_json::from_str::<Datapaths>(content).map_err(DataError::from) serde_json::from_str::<Datapaths>(content).map_err(DataError::from)
} }

Loading…
Cancel
Save