use dinah::memory::{Buffer, BufferPushError};
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let mut samples = Buffer::try_with_capacity(3)?;
samples.try_extend_from_slice(&[12_u16, 18])?;
samples
.try_push(24)
.expect("the configured capacity has one free slot");
println!(
"samples={:?} len={} capacity={} full={}",
samples.as_slice(),
samples.len(),
samples.capacity(),
samples.is_full()
);
match samples.try_push(30) {
Ok(()) => unreachable!("the configured capacity is already full"),
Err(BufferPushError::Full(value)) => println!("rejected={value}"),
}
samples.clear(); samples
.try_push(42)
.map_err(|_| std::io::Error::other("buffer rejected insertion after clear"))?;
println!("after_clear={:?}", samples.as_slice());
Ok(())
}