use bytesbuf::BytesView;
use bytesbuf::mem::GlobalPool;
fn main() {
let memory = GlobalPool::new();
let hello_world = BytesView::copied_from_slice(b"Hello, world!", &memory);
inspect_bytes(&hello_world);
let hello = hello_world.range(0..5);
let world = hello_world.range(7..12);
inspect_bytes(&hello);
inspect_bytes(&world);
let hello_world_reconstructed = BytesView::from_views([hello, world]);
inspect_bytes(&hello_world_reconstructed);
let mut buf = memory.reserve(1024);
buf.put_slice(b"The quick brown fox says \"".as_slice());
buf.put_bytes(hello_world_reconstructed);
buf.put_slice(b"\" and jumps over the lazy dog.".as_slice());
let fox_story = buf.consume_all();
inspect_bytes(&fox_story);
}
fn inspect_bytes(bytes: &BytesView) {
let len = bytes.len();
let mut slice_lengths = Vec::new();
let mut bytes = bytes.clone();
while !bytes.is_empty() {
let slice = bytes.first_slice();
slice_lengths.push(slice.len());
bytes.advance(slice.len());
}
println!("Inspected a view over {len} bytes with slice lengths: {slice_lengths:?}");
}