A flexible byte pool.
use byte_pool::BytePool;
// Create a pool
let pool = BytePool::<Vec<u8>>::new();
// Allocate and copy from existing bytes.
let payload = pool.alloc_from_slice(b"hello");
assert_eq!(&payload[..], b"hello");
// Allocate a writable frame and shrink it after recv/write.
let mut frame = pool.alloc_and_fill(1024);
let received = 128;
frame.set_filled_len(received);
assert_eq!(frame.len(), received);
// Returns the underlying memory to the pool.
drop(payload);
drop(frame);
// Frees all memory in the pool.
drop(pool);Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.