Skip to content

Commit dce1f30

Browse files
committed
make with_hasher_in const (consistent with with_hasher)
Signed-off-by: TennyZhuang <zty0826@gmail.com>
1 parent c0247fa commit dce1f30

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/map.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ impl<K, V, S, A: Allocator + Clone> HashMap<K, V, S, A> {
429429
/// Creates an empty `HashMap` which will use the given hash builder to hash
430430
/// keys. It will be allocated with the given allocator.
431431
///
432-
/// The created map has the default initial capacity.
432+
/// The hash map is initially created with a capacity of 0, so it will not
433+
/// allocate until it is first inserted into.
433434
///
434435
/// Warning: `hash_builder` is normally randomly generated, and
435436
/// is designed to allow HashMaps to be resistant to attacks that
@@ -447,7 +448,7 @@ impl<K, V, S, A: Allocator + Clone> HashMap<K, V, S, A> {
447448
/// map.insert(1, 2);
448449
/// ```
449450
#[cfg_attr(feature = "inline-more", inline)]
450-
pub fn with_hasher_in(hash_builder: S, alloc: A) -> Self {
451+
pub const fn with_hasher_in(hash_builder: S, alloc: A) -> Self {
451452
Self {
452453
hash_builder,
453454
table: RawTable::new_in(alloc),

src/raw/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl<T, A: Allocator + Clone> RawTable<T, A> {
426426
/// leave the data pointer dangling since that bucket is never written to
427427
/// due to our load factor forcing us to always have at least 1 free bucket.
428428
#[inline]
429-
pub fn new_in(alloc: A) -> Self {
429+
pub const fn new_in(alloc: A) -> Self {
430430
Self {
431431
table: RawTableInner::new_in(alloc),
432432
marker: PhantomData,

src/set.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ impl<T, S> HashSet<T, S, Global> {
387387
/// Creates a new empty hash set which will use the given hasher to hash
388388
/// keys.
389389
///
390-
/// The hash set is also created with the default initial capacity.
390+
/// The hash set is initially created with a capacity of 0, so it will not
391+
/// allocate until it is first inserted into.
391392
///
392393
/// Warning: `hasher` is normally randomly generated, and
393394
/// is designed to allow `HashSet`s to be resistant to attacks that
@@ -464,7 +465,8 @@ where
464465
/// Creates a new empty hash set which will use the given hasher to hash
465466
/// keys.
466467
///
467-
/// The hash set is also created with the default initial capacity.
468+
/// The hash set is initially created with a capacity of 0, so it will not
469+
/// allocate until it is first inserted into.
468470
///
469471
/// Warning: `hasher` is normally randomly generated, and
470472
/// is designed to allow `HashSet`s to be resistant to attacks that
@@ -482,7 +484,7 @@ where
482484
/// set.insert(2);
483485
/// ```
484486
#[cfg_attr(feature = "inline-more", inline)]
485-
pub fn with_hasher_in(hasher: S, alloc: A) -> Self {
487+
pub const fn with_hasher_in(hasher: S, alloc: A) -> Self {
486488
Self {
487489
map: HashMap::with_hasher_in(hasher, alloc),
488490
}

0 commit comments

Comments
 (0)