Skip to content

Commit

Permalink
ensure len and capacity methods reflect their intentions
Browse files Browse the repository at this point in the history
  • Loading branch information
neevek committed Apr 4, 2023
1 parent 2a50848 commit f39ad07
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/poolable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Default + Clone> Poolable for Vec<T> {
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]
}
Expand All @@ -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())
}
Expand Down

0 comments on commit f39ad07

Please sign in to comment.