diff --git a/src/poolable.rs b/src/poolable.rs index 23fd0cc..125bc9c 100644 --- a/src/poolable.rs +++ b/src/poolable.rs @@ -3,15 +3,20 @@ use std::hash::{BuildHasher, Hash}; /// The trait required to be able to use a type in `BytePool`. pub trait Poolable { + fn len(&self) -> usize; fn capacity(&self) -> usize; fn alloc(size: usize) -> Self; } impl Poolable for Vec { - fn capacity(&self) -> usize { + fn len(&self) -> usize { self.len() } + fn capacity(&self) -> usize { + self.capacity() + } + fn alloc(size: usize) -> Self { vec![T::default(); size] } @@ -22,10 +27,14 @@ where K: Eq + Hash, S: BuildHasher + Default, { - fn capacity(&self) -> usize { + fn len(&self) -> usize { self.len() } + fn capacity(&self) -> usize { + self.capacity() + } + fn alloc(size: usize) -> Self { HashMap::with_capacity_and_hasher(size, Default::default()) }