From 5c1d5d660d6c9fee8bc0fe5b177d489a1972ac7a Mon Sep 17 00:00:00 2001 From: Adam Cimarosti Date: Thu, 3 Oct 2024 10:02:20 +0100 Subject: [PATCH] removed redundant method and improved assertions of the original --- src/vec.rs | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/vec.rs b/src/vec.rs index bbfa611..d0f988e 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -22,13 +22,6 @@ impl Vec { self.inner.allocator() } - #[inline] - pub fn try_with_capacity_in(capacity: usize, alloc: A) -> Result { - Ok(Self { - inner: InnerVec::try_with_capacity_in(capacity, alloc)?, - }) - } - #[inline] pub fn capacity(&self) -> usize { self.inner.capacity() @@ -41,9 +34,9 @@ impl Vec { #[inline] pub fn with_capacity_in(capacity: usize, alloc: A) -> Result { - let mut vec = Self::new_in(alloc); - vec.reserve(capacity)?; - Ok(vec) + Ok(Self { + inner: InnerVec::try_with_capacity_in(capacity, alloc)?, + }) } #[inline] @@ -378,7 +371,10 @@ mod tests { fn test_with_capacity_in() { let wma = WatermarkAllocator::new(32); let vec: Vec = Vec::with_capacity_in(4, wma.clone()).unwrap(); + assert_eq!(vec.len(), 0); + assert_eq!(vec.as_slice(), &[]); assert_eq!(vec.inner.capacity(), 4); + assert_eq!(wma.in_use(), 4 * size_of::()); let _err: TryReserveError = Vec::::with_capacity_in(5, wma).unwrap_err(); } @@ -613,16 +609,6 @@ mod tests { assert_eq!(wma.in_use(), 0); } - #[test] - fn try_with_capacity_in() { - let wma = WatermarkAllocator::new(64); - let vec: Vec = Vec::try_with_capacity_in(64, wma.clone()).unwrap(); - assert_eq!(vec.len(), 0); - assert_eq!(vec.as_slice(), &[]); - assert_eq!(vec.capacity(), 64); - assert_eq!(wma.in_use(), 64); - } - #[test] fn test_truncate() { let wma = WatermarkAllocator::new(32);