From f39ad070178fa61798f468709a251a9c0ed99328 Mon Sep 17 00:00:00 2001 From: neevek Date: Wed, 5 Apr 2023 00:26:16 +0800 Subject: [PATCH] ensure len and capacity methods reflect their intentions --- src/poolable.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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()) }