diff --git a/Cargo.toml b/Cargo.toml index 3267fc8..2885685 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "minecraft-data-rs" -version = "0.4.4" +version = "0.4.5" authors = ["trivernis "] edition = "2018" readme = "README.md" diff --git a/src/api/biomes.rs b/src/api/biomes.rs index 4505b24..4368417 100644 --- a/src/api/biomes.rs +++ b/src/api/biomes.rs @@ -3,7 +3,6 @@ use crate::models::biome::Biome; use crate::models::version::Version; use crate::DataResult; use std::collections::HashMap; -use std::iter::FromIterator; use std::sync::Arc; pub struct Biomes { @@ -26,7 +25,7 @@ impl Biomes { /// Returns the biomes indexed by id pub fn biomes(&self) -> DataResult> { let biomes = self.biomes_array()?; - let biomes_map = HashMap::from_iter(biomes.into_iter().map(|b| (b.id, b))); + let biomes_map = biomes.into_iter().map(|b| (b.id, b)).collect(); Ok(biomes_map) } @@ -34,7 +33,7 @@ impl Biomes { /// Returns the biomes indexed by name pub fn biomes_by_name(&self) -> DataResult> { let biomes = self.biomes_array()?; - let biomes_map = HashMap::from_iter(biomes.into_iter().map(|b| (b.name.clone(), b))); + let biomes_map = biomes.into_iter().map(|b| (b.name.clone(), b)).collect(); Ok(biomes_map) } diff --git a/src/api/blocks.rs b/src/api/blocks.rs index 45c189f..2b14dc6 100644 --- a/src/api/blocks.rs +++ b/src/api/blocks.rs @@ -4,7 +4,6 @@ use crate::models::block_collision_shapes::BlockCollisionShapes; use crate::models::version::Version; use crate::DataResult; use std::collections::HashMap; -use std::iter::FromIterator; use std::sync::Arc; pub struct Blocks { @@ -27,7 +26,7 @@ impl Blocks { /// Returns the blocks indexed by ID pub fn blocks(&self) -> DataResult> { let blocks = self.blocks_array()?; - let blocks_map = HashMap::from_iter(blocks.into_iter().map(|b| (b.id, b))); + let blocks_map = blocks.into_iter().map(|b| (b.id, b)).collect(); Ok(blocks_map) } @@ -35,7 +34,7 @@ impl Blocks { /// Returns the blocks indexed by name pub fn blocks_by_name(&self) -> DataResult> { let blocks = self.blocks_array()?; - let blocks_map = HashMap::from_iter(blocks.into_iter().map(|b| (b.name.clone(), b))); + let blocks_map = blocks.into_iter().map(|b| (b.name.clone(), b)).collect(); Ok(blocks_map) } diff --git a/src/api/enchantments.rs b/src/api/enchantments.rs index 6b006ac..026fd48 100644 --- a/src/api/enchantments.rs +++ b/src/api/enchantments.rs @@ -4,7 +4,6 @@ use crate::models::version::Version; use crate::{DataError, DataResult}; use itertools::*; use std::collections::HashMap; -use std::iter::FromIterator; use std::sync::Arc; #[derive(Clone, Debug)] @@ -26,28 +25,30 @@ impl Enchantments { /// Returns a map of enchantments indexed by ID pub fn enchantments(&self) -> DataResult> { - Ok(HashMap::from_iter( - self.enchantments_array()?.into_iter().map(|e| (e.id, e)), - )) + Ok(self + .enchantments_array()? + .into_iter() + .map(|e| (e.id, e)) + .collect()) } /// Returns a map of enchantments indexed by Name pub fn enchantments_by_name(&self) -> DataResult> { - Ok(HashMap::from_iter( - self.enchantments_array()? - .into_iter() - .map(|e| (e.name.clone(), e)), - )) + Ok(self + .enchantments_array()? + .into_iter() + .map(|e| (e.name.clone(), e)) + .collect()) } /// Returns enchantments grouped by category pub fn enchantments_by_category(&self) -> DataResult>> { - Ok(HashMap::from_iter( - self.enchantments_array()? - .into_iter() - .group_by(|e| e.category.clone()) - .into_iter() - .map(|(key, group)| (key, group.collect())), - )) + Ok(self + .enchantments_array()? + .into_iter() + .group_by(|e| e.category.clone()) + .into_iter() + .map(|(key, group)| (key, group.collect())) + .collect()) } } diff --git a/src/api/entities.rs b/src/api/entities.rs index d6d31b6..04ab051 100644 --- a/src/api/entities.rs +++ b/src/api/entities.rs @@ -3,7 +3,6 @@ use crate::models::entity::Entity; use crate::models::version::Version; use crate::DataResult; use std::collections::HashMap; -use std::iter::FromIterator; use std::sync::Arc; pub struct Entities { @@ -26,7 +25,7 @@ impl Entities { /// Returns entities indexed by name pub fn entities_by_name(&self) -> DataResult> { let entities = self.entities_array()?; - let entities_map = HashMap::from_iter(entities.into_iter().map(|e| (e.name.clone(), e))); + let entities_map = entities.into_iter().map(|e| (e.name.clone(), e)).collect(); Ok(entities_map) } @@ -34,7 +33,7 @@ impl Entities { /// Returns entities indexed by id pub fn entities(&self) -> DataResult> { let entities = self.entities_array()?; - let entities_map = HashMap::from_iter(entities.into_iter().map(|e| (e.id, e))); + let entities_map = entities.into_iter().map(|e| (e.id, e)).collect(); Ok(entities_map) } diff --git a/src/api/foods.rs b/src/api/foods.rs index 28c108e..dc53208 100644 --- a/src/api/foods.rs +++ b/src/api/foods.rs @@ -3,7 +3,6 @@ use crate::models::food::Food; use crate::models::version::Version; use crate::DataResult; use std::collections::HashMap; -use std::iter::FromIterator; use std::sync::Arc; pub struct Foods { @@ -26,7 +25,7 @@ impl Foods { /// Returns food indexed by id pub fn foods(&self) -> DataResult> { let foods = self.foods_array()?; - let food_map = HashMap::from_iter(foods.into_iter().map(|f| (f.id, f))); + let food_map = foods.into_iter().map(|f| (f.id, f)).collect(); Ok(food_map) } @@ -34,7 +33,7 @@ impl Foods { /// Returns food indexed by name pub fn foods_by_name(&self) -> DataResult> { let foods = self.foods_array()?; - let food_map = HashMap::from_iter(foods.into_iter().map(|f| (f.name.clone(), f))); + let food_map = foods.into_iter().map(|f| (f.name.clone(), f)).collect(); Ok(food_map) } diff --git a/src/api/items.rs b/src/api/items.rs index ab582ee..411df08 100644 --- a/src/api/items.rs +++ b/src/api/items.rs @@ -3,7 +3,6 @@ use crate::models::item::Item; use crate::models::version::Version; use crate::{DataError, DataResult}; use std::collections::HashMap; -use std::iter::FromIterator; use std::sync::Arc; /// API to access item information @@ -25,15 +24,19 @@ impl Items { /// Returns the items indexed by name pub fn items_by_name(&self) -> DataResult> { - Ok(HashMap::from_iter( - self.items_array()?.into_iter().map(|i| (i.name.clone(), i)), - )) + Ok(self + .items_array()? + .into_iter() + .map(|i| (i.name.clone(), i)) + .collect()) } /// Returns the items indexed by ID pub fn items(&self) -> DataResult> { - Ok(HashMap::from_iter( - self.items_array()?.into_iter().map(|i| (i.id.clone(), i)), - )) + Ok(self + .items_array()? + .into_iter() + .map(|i| (i.id.clone(), i)) + .collect()) } } diff --git a/src/api/loot.rs b/src/api/loot.rs index 02f46c8..7b18ea7 100644 --- a/src/api/loot.rs +++ b/src/api/loot.rs @@ -4,7 +4,6 @@ use crate::models::entity_loot::EntityLoot; use crate::models::version::Version; use crate::DataResult; use std::collections::HashMap; -use std::iter::FromIterator; use std::sync::Arc; /// API to access item information @@ -28,7 +27,7 @@ impl Loot { /// Returns the entity loot indexed by entity name pub fn entity_loot(&self) -> DataResult> { let loot = self.entity_loot_array()?; - let loot_map = HashMap::from_iter(loot.into_iter().map(|l| (l.entity.clone(), l))); + let loot_map = loot.into_iter().map(|l| (l.entity.clone(), l)).collect(); Ok(loot_map) } @@ -44,7 +43,7 @@ impl Loot { /// Returns the block loot indexed by block name pub fn block_loot(&self) -> DataResult> { let loot = self.block_loot_array()?; - let loot_map = HashMap::from_iter(loot.into_iter().map(|l| (l.block.clone(), l))); + let loot_map = loot.into_iter().map(|l| (l.block.clone(), l)).collect(); Ok(loot_map) } diff --git a/src/api/versions.rs b/src/api/versions.rs index 61df53d..516ce10 100644 --- a/src/api/versions.rs +++ b/src/api/versions.rs @@ -3,7 +3,6 @@ use crate::models::version::Version; use crate::{DataError, DataResult}; use itertools::Itertools; use std::collections::HashMap; -use std::iter::FromIterator; /// Returns the unsorted list of versions pub fn versions() -> DataResult> { @@ -15,11 +14,10 @@ pub fn versions() -> DataResult> { /// Returns the versions indexed by minecraft version pub fn versions_by_minecraft_version() -> DataResult> { - let indexed_versions = HashMap::from_iter( - versions()? - .into_iter() - .map(|v| (v.minecraft_version.clone(), v)), - ); + let indexed_versions = versions()? + .into_iter() + .map(|v| (v.minecraft_version.clone(), v)) + .collect(); Ok(indexed_versions) }