diff --git a/src/map.rs b/src/map.rs index ab1128879f..f9b6ae9689 100644 --- a/src/map.rs +++ b/src/map.rs @@ -395,6 +395,12 @@ impl HashMap { } impl HashMap { + /// Returns a reference to the underlying allocator. + #[inline] + pub fn allocator(&self) -> &A { + self.table.allocator() + } + /// Creates an empty `HashMap` which will use the given hash builder to hash /// keys. It will be allocated with the given allocator. /// diff --git a/src/raw/mod.rs b/src/raw/mod.rs index 6202534af4..d0418e387d 100644 --- a/src/raw/mod.rs +++ b/src/raw/mod.rs @@ -492,6 +492,12 @@ impl RawTable { } } + /// Returns a reference to the underlying allocator. + #[inline] + pub fn allocator(&self) -> &A { + &self.table.alloc + } + /// Deallocates the table without dropping any entries. #[cfg_attr(feature = "inline-more", inline)] unsafe fn free_buckets(&mut self) { diff --git a/src/set.rs b/src/set.rs index d59183b5ca..bf3faee60d 100644 --- a/src/set.rs +++ b/src/set.rs @@ -454,6 +454,12 @@ impl HashSet where A: Allocator + Clone, { + /// Returns a reference to the underlying allocator. + #[inline] + pub fn allocator(&self) -> &A { + self.map.allocator() + } + /// Creates a new empty hash set which will use the given hasher to hash /// keys. ///