use bstack::BStack;
use std::io;
fn main() -> io::Result<()> {
let stack = BStack::open("buffer_reuse_example.bstack")?;
stack.push(b"First message\n")?; stack.push(b"Second message\n")?; stack.push(b"Third message\n")?;
println!("Stack length: {} bytes", stack.len()?);
let mut buf = vec![0u8; 14]; stack.get_into(0, &mut buf)?;
println!("Read with get_into: {:?}", String::from_utf8_lossy(&buf));
let mut pop_buf = vec![0u8; 14];
stack.pop_into(&mut pop_buf)?;
println!(
"Popped with pop_into: {:?}",
String::from_utf8_lossy(&pop_buf)
);
println!("Stack length after pop: {} bytes", stack.len()?);
let remaining = stack.peek(0)?;
println!("Remaining data: {:?}", String::from_utf8_lossy(&remaining));
Ok(())
}