Loading RustViz Engine...
Simulate buffer ownership passing between worker threads with std::mem::take.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
pub struct BufferPool {
pool: Vec<Vec<u8>>,
}
impl BufferPool {
pub fn new() -> Self { Self { pool: Vec::new() } }
pub fn acquire(&mut self, capacity: usize) -> Vec<u8> {
self.pool.pop().unwrap_or_else(|| Vec::with_capacity(capacity))
}
pub fn release(&mut self, mut buf: Vec<u8>) {
buf.clear();
self.pool.push(buf);
}
}