From c069bdcd6516a31939d4a4129c93bd2e4624bdf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20M=C5=93ller?= Date: Fri, 11 Feb 2022 03:55:11 +0100 Subject: [PATCH] Added From for AHashSet & AHashMap. (#109) --- src/hash_map.rs | 18 ++++++++++++++++++ src/hash_set.rs | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/hash_map.rs b/src/hash_map.rs index ec8fa43..03688d9 100644 --- a/src/hash_map.rs +++ b/src/hash_map.rs @@ -25,6 +25,24 @@ impl From> for AHashMap { } } +impl From<[(K, V); N]> for AHashMap +where + K: Eq + Hash, +{ + /// # Examples + /// + /// ``` + /// use ahash::AHashMap; + /// + /// let map1 = AHashMap::from([(1, 2), (3, 4)]); + /// let map2: AHashMap<_, _> = [(1, 2), (3, 4)].into(); + /// assert_eq!(map1, map2); + /// ``` + fn from(arr: [(K, V); N]) -> Self { + Self::from_iter(arr) + } +} + impl Into> for AHashMap { fn into(self) -> HashMap { self.0 diff --git a/src/hash_set.rs b/src/hash_set.rs index 9766b67..1d73cf6 100644 --- a/src/hash_set.rs +++ b/src/hash_set.rs @@ -22,6 +22,24 @@ impl From> for AHashSet { } } +impl From<[T; N]> for AHashSet +where + T: Eq + Hash, +{ + /// # Examples + /// + /// ``` + /// use ahash::AHashSet; + /// + /// let set1 = AHashSet::from([1, 2, 3, 4]); + /// let set2: AHashSet<_> = [1, 2, 3, 4].into(); + /// assert_eq!(set1, set2); + /// ``` + fn from(arr: [T; N]) -> Self { + Self::from_iter(arr) + } +} + impl Into> for AHashSet { fn into(self) -> HashSet { self.0