Skip to content

Commit

Permalink
Added From<array> for AHashSet & AHashMap. (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
virtualritz committed Feb 11, 2022
1 parent e77cab8 commit c069bdc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/hash_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ impl<K, V> From<HashMap<K, V, crate::RandomState>> for AHashMap<K, V> {
}
}

impl<K, V, const N: usize> From<[(K, V); N]> for AHashMap<K, V>
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<K, V> Into<HashMap<K, V, crate::RandomState>> for AHashMap<K, V> {
fn into(self) -> HashMap<K, V, crate::RandomState> {
self.0
Expand Down
18 changes: 18 additions & 0 deletions src/hash_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ impl<T> From<HashSet<T, crate::RandomState>> for AHashSet<T> {
}
}

impl<T, const N: usize> From<[T; N]> for AHashSet<T>
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<T> Into<HashSet<T, crate::RandomState>> for AHashSet<T> {
fn into(self) -> HashSet<T, crate::RandomState> {
self.0
Expand Down

0 comments on commit c069bdc

Please sign in to comment.