Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ impl<K, V> HashMap<K, V, DefaultHashBuilder> {
/// assert_eq!(map.len(), 0);
/// assert_eq!(map.capacity(), 0);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn new() -> Self {
Self::default()
Expand Down Expand Up @@ -296,6 +297,7 @@ impl<K, V> HashMap<K, V, DefaultHashBuilder> {
/// assert_eq!(map.len(), 0);
/// assert!(map.capacity() >= 10);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn with_capacity(capacity: usize) -> Self {
Self::with_capacity_and_hasher(capacity, DefaultHashBuilder::default())
Expand Down Expand Up @@ -342,6 +344,7 @@ impl<K, V, A: Allocator> HashMap<K, V, DefaultHashBuilder, A> {
/// // And it also allocates some capacity
/// assert!(map.capacity() > 1);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn new_in(alloc: A) -> Self {
Self::with_hasher_in(DefaultHashBuilder::default(), alloc)
Expand Down Expand Up @@ -390,6 +393,7 @@ impl<K, V, A: Allocator> HashMap<K, V, DefaultHashBuilder, A> {
/// // But its capacity isn't changed
/// assert_eq!(map.capacity(), empty_map_capacity)
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
Self::with_capacity_and_hasher_in(capacity, DefaultHashBuilder::default(), alloc)
Expand Down Expand Up @@ -429,6 +433,7 @@ impl<K, V, S> HashMap<K, V, S> {
///
/// map.insert(1, 2);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
#[cfg_attr(feature = "rustc-dep-of-std", rustc_const_stable_indirect)]
pub const fn with_hasher(hash_builder: S) -> Self {
Expand Down Expand Up @@ -470,6 +475,7 @@ impl<K, V, S> HashMap<K, V, S> {
///
/// map.insert(1, 2);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self {
Self {
Expand Down Expand Up @@ -512,6 +518,7 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
/// let mut map = HashMap::with_hasher(s);
/// map.insert(1, 2);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
#[cfg_attr(feature = "rustc-dep-of-std", rustc_const_stable_indirect)]
pub const fn with_hasher_in(hash_builder: S, alloc: A) -> Self {
Expand Down Expand Up @@ -547,6 +554,7 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
/// let mut map = HashMap::with_capacity_and_hasher(10, s);
/// map.insert(1, 2);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn with_capacity_and_hasher_in(capacity: usize, hash_builder: S, alloc: A) -> Self {
Self {
Expand Down
8 changes: 8 additions & 0 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl<T> HashSet<T, DefaultHashBuilder> {
/// use hashbrown::HashSet;
/// let set: HashSet<i32> = HashSet::new();
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn new() -> Self {
Self {
Expand Down Expand Up @@ -178,6 +179,7 @@ impl<T> HashSet<T, DefaultHashBuilder> {
/// let set: HashSet<i32> = HashSet::with_capacity(10);
/// assert!(set.capacity() >= 10);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn with_capacity(capacity: usize) -> Self {
Self {
Expand Down Expand Up @@ -210,6 +212,7 @@ impl<T: Hash + Eq, A: Allocator> HashSet<T, DefaultHashBuilder, A> {
/// use hashbrown::HashSet;
/// let set: HashSet<i32> = HashSet::new();
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn new_in(alloc: A) -> Self {
Self {
Expand Down Expand Up @@ -240,6 +243,7 @@ impl<T: Hash + Eq, A: Allocator> HashSet<T, DefaultHashBuilder, A> {
/// let set: HashSet<i32> = HashSet::with_capacity(10);
/// assert!(set.capacity() >= 10);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
Self {
Expand Down Expand Up @@ -455,6 +459,7 @@ impl<T, S> HashSet<T, S, Global> {
/// let mut set = HashSet::with_hasher(s);
/// set.insert(2);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
#[cfg_attr(feature = "rustc-dep-of-std", rustc_const_stable_indirect)]
pub const fn with_hasher(hasher: S) -> Self {
Expand Down Expand Up @@ -492,6 +497,7 @@ impl<T, S> HashSet<T, S, Global> {
/// let mut set = HashSet::with_capacity_and_hasher(10, s);
/// set.insert(1);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self {
Self {
Expand Down Expand Up @@ -539,6 +545,7 @@ where
/// let mut set = HashSet::with_hasher(s);
/// set.insert(2);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
#[cfg_attr(feature = "rustc-dep-of-std", rustc_const_stable_indirect)]
pub const fn with_hasher_in(hasher: S, alloc: A) -> Self {
Expand Down Expand Up @@ -576,6 +583,7 @@ where
/// let mut set = HashSet::with_capacity_and_hasher(10, s);
/// set.insert(1);
/// ```
#[must_use]
#[cfg_attr(feature = "inline-more", inline)]
pub fn with_capacity_and_hasher_in(capacity: usize, hasher: S, alloc: A) -> Self {
Self {
Expand Down
4 changes: 4 additions & 0 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl<T> HashTable<T, Global> {
/// assert_eq!(table.len(), 0);
/// assert_eq!(table.capacity(), 0);
/// ```
#[must_use]
pub const fn new() -> Self {
Self {
raw: RawTable::new(),
Expand All @@ -85,6 +86,7 @@ impl<T> HashTable<T, Global> {
/// assert_eq!(table.len(), 0);
/// assert!(table.capacity() >= 10);
/// ```
#[must_use]
pub fn with_capacity(capacity: usize) -> Self {
Self {
raw: RawTable::with_capacity(capacity),
Expand Down Expand Up @@ -133,6 +135,7 @@ where
/// # test()
/// # }
/// ```
#[must_use]
pub const fn new_in(alloc: A) -> Self {
Self {
raw: RawTable::new_in(alloc),
Expand Down Expand Up @@ -181,6 +184,7 @@ where
/// # test()
/// # }
/// ```
#[must_use]
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
Self {
raw: RawTable::with_capacity_in(capacity, alloc),
Expand Down