use crate::word_buffer::WordBuffer;
#[derive(Default)]
pub struct Buffer(pub(crate) WordBuffer);
impl Buffer {
pub fn new() -> Self {
Self::default()
}
pub fn with_capacity(capacity: usize) -> Self {
Self(WithCapacity::with_capacity(capacity))
}
#[cfg(test)]
pub(crate) fn capacity(&self) -> usize {
self.0.capacity()
}
}
pub trait WithCapacity {
fn capacity(&self) -> usize;
fn with_capacity(capacity: usize) -> Self;
}
#[cfg(all(test, not(miri)))]
mod tests {
use crate::bit_buffer::BitBuffer;
use crate::buffer::WithCapacity;
use crate::word_buffer::WordBuffer;
use paste::paste;
macro_rules! test_with_capacity {
($name:ty, $t:ty) => {
paste! {
#[test]
fn [<test_ $name _with_capacity>]() {
for cap in 0..200 {
let buf = $t::with_capacity(cap);
assert!(buf.capacity() >= cap, "with_capacity: {cap}, capacity {}", buf.capacity());
}
}
}
}
}
test_with_capacity!(bit_buffer, BitBuffer);
test_with_capacity!(word_buffer, WordBuffer);
}