Skip to content

Commit

Permalink
removed redundant method and improved assertions of the original
Browse files Browse the repository at this point in the history
  • Loading branch information
amunra committed Oct 3, 2024
1 parent 99da4f0 commit 5c1d5d6
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ impl<T, A: Allocator> Vec<T, A> {
self.inner.allocator()
}

#[inline]
pub fn try_with_capacity_in(capacity: usize, alloc: A) -> Result<Self, TryReserveError> {
Ok(Self {
inner: InnerVec::try_with_capacity_in(capacity, alloc)?,
})
}

#[inline]
pub fn capacity(&self) -> usize {
self.inner.capacity()
Expand All @@ -41,9 +34,9 @@ impl<T, A: Allocator> Vec<T, A> {

#[inline]
pub fn with_capacity_in(capacity: usize, alloc: A) -> Result<Self, TryReserveError> {
let mut vec = Self::new_in(alloc);
vec.reserve(capacity)?;
Ok(vec)
Ok(Self {
inner: InnerVec::try_with_capacity_in(capacity, alloc)?,
})
}

#[inline]
Expand Down Expand Up @@ -378,7 +371,10 @@ mod tests {
fn test_with_capacity_in() {
let wma = WatermarkAllocator::new(32);
let vec: Vec<usize, _> = 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::<usize>());

let _err: TryReserveError = Vec::<i8, _>::with_capacity_in(5, wma).unwrap_err();
}
Expand Down Expand Up @@ -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<u8, _> = 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);
Expand Down

0 comments on commit 5c1d5d6

Please sign in to comment.