Skip to content

Commit f39ad07

Browse files
committed
ensure len and capacity methods reflect their intentions
1 parent 2a50848 commit f39ad07

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/poolable.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@ use std::hash::{BuildHasher, Hash};
33

44
/// The trait required to be able to use a type in `BytePool`.
55
pub trait Poolable {
6+
fn len(&self) -> usize;
67
fn capacity(&self) -> usize;
78
fn alloc(size: usize) -> Self;
89
}
910

1011
impl<T: Default + Clone> Poolable for Vec<T> {
11-
fn capacity(&self) -> usize {
12+
fn len(&self) -> usize {
1213
self.len()
1314
}
1415

16+
fn capacity(&self) -> usize {
17+
self.capacity()
18+
}
19+
1520
fn alloc(size: usize) -> Self {
1621
vec![T::default(); size]
1722
}
@@ -22,10 +27,14 @@ where
2227
K: Eq + Hash,
2328
S: BuildHasher + Default,
2429
{
25-
fn capacity(&self) -> usize {
30+
fn len(&self) -> usize {
2631
self.len()
2732
}
2833

34+
fn capacity(&self) -> usize {
35+
self.capacity()
36+
}
37+
2938
fn alloc(size: usize) -> Self {
3039
HashMap::with_capacity_and_hasher(size, Default::default())
3140
}

0 commit comments

Comments
 (0)