Skip to content

Commit d1d4847

Browse files
committed
Implement From<[T; N]> for HashSet
1 parent 6cbdd5a commit d1d4847

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/set.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,27 @@ where
11591159
}
11601160
}
11611161

1162+
// The default hasher is used to match the std implementation signature
1163+
// see https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1010-1026
1164+
impl<T, A, const N: usize> From<[T; N]> for HashSet<T, DefaultHashBuilder, A>
1165+
where
1166+
T: Eq + Hash,
1167+
A: Default + Allocator + Clone,
1168+
{
1169+
/// # Examples
1170+
///
1171+
/// ```
1172+
/// use hashbrown::HashSet;
1173+
///
1174+
/// let set1 = HashSet::from([1, 2, 3, 4]);
1175+
/// let set2: HashSet<_> = [1, 2, 3, 4].into();
1176+
/// assert_eq!(set1, set2);
1177+
/// ```
1178+
fn from(arr: [T; N]) -> Self {
1179+
arr.into_iter().collect()
1180+
}
1181+
}
1182+
11621183
impl<T, S, A> Extend<T> for HashSet<T, S, A>
11631184
where
11641185
T: Eq + Hash,

0 commit comments

Comments
 (0)