Skip to content

Commit

Permalink
allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
amunra committed Sep 27, 2024
1 parent fe272c2 commit 0f04f08
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ impl<T, A: Allocator> Vec<T, A> {
}
}

pub fn allocator(&self) -> &A {
self.inner.allocator()
}

#[inline]
pub fn capacity(&self) -> usize {
self.inner.capacity()
Expand Down Expand Up @@ -273,7 +277,7 @@ mod tests {
#[test]
fn test_basics() {
let wma = WatermarkAllocator::new(32);
let mut vec = Vec::new_in(wma);
let mut vec = Vec::new_in(wma.clone());
assert_eq!(vec.len(), 0);
assert_eq!(vec.capacity(), 0);
assert!(vec.is_empty());
Expand All @@ -285,6 +289,14 @@ mod tests {
vec.push(4).unwrap();
assert_eq!(vec.len(), 4);
assert_eq!(vec.capacity(), 4);
assert_eq!(
wma.in_use.load(Ordering::SeqCst),
vec.capacity() * size_of::<i32>()
);
assert_eq!(
vec.allocator().in_use.load(Ordering::SeqCst),
vec.capacity() * size_of::<i32>()
);
let _err: TryReserveError = vec.push(5).unwrap_err();
assert_eq!(vec.as_slice(), &[1, 2, 3, 4]);
assert_eq!(vec.len(), 4);
Expand Down

0 comments on commit 0f04f08

Please sign in to comment.