Skip to content

Commit 53644bd

Browse files
committed
Auto merge of #174 - jonhoo:try-with-cap, r=Amanieu
Expose RawTable::try_with_capacity Fixes #169.
2 parents ace3ac2 + c78df38 commit 53644bd

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/raw/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl<T> RawTable<T> {
417417

418418
/// Attempts to allocate a new hash table with at least enough capacity
419419
/// for inserting the given number of elements without reallocating.
420-
fn try_with_capacity(
420+
fn fallible_with_capacity(
421421
capacity: usize,
422422
fallability: Fallibility,
423423
) -> Result<Self, TryReserveError> {
@@ -435,10 +435,17 @@ impl<T> RawTable<T> {
435435
}
436436
}
437437

438+
/// Attempts to allocate a new hash table with at least enough capacity
439+
/// for inserting the given number of elements without reallocating.
440+
#[cfg(feature = "raw")]
441+
pub fn try_with_capacity(capacity: usize) -> Result<Self, TryReserveError> {
442+
Self::fallible_with_capacity(capacity, Fallibility::Fallible)
443+
}
444+
438445
/// Allocates a new hash table with at least enough capacity for inserting
439446
/// the given number of elements without reallocating.
440447
pub fn with_capacity(capacity: usize) -> Self {
441-
Self::try_with_capacity(capacity, Fallibility::Infallible)
448+
Self::fallible_with_capacity(capacity, Fallibility::Infallible)
442449
.unwrap_or_else(|_| unsafe { hint::unreachable_unchecked() })
443450
}
444451

@@ -834,7 +841,7 @@ impl<T> RawTable<T> {
834841
debug_assert!(self.items <= capacity);
835842

836843
// Allocate and initialize the new table.
837-
let mut new_table = Self::try_with_capacity(capacity, fallability)?;
844+
let mut new_table = Self::fallible_with_capacity(capacity, fallability)?;
838845
new_table.growth_left -= self.items;
839846
new_table.items = self.items;
840847

0 commit comments

Comments
 (0)