use std::io::IoSlice;
pub use bytesbuf::mem::{GlobalPool, Memory};
pub use bytesbuf::{BytesBuf, BytesView};
pub type Chunk = BytesView;
thread_local! {
static POOL: GlobalPool = GlobalPool::new();
}
#[must_use]
pub fn memory() -> GlobalPool {
POOL.with(Clone::clone)
}
#[must_use]
pub fn from_bytes(b: bytes::Bytes) -> Chunk {
b.into()
}
#[must_use]
pub fn from_static(b: &'static [u8]) -> Chunk {
bytes::Bytes::from_static(b).into()
}
#[must_use]
pub fn copy_from_slice(b: &[u8]) -> Chunk {
BytesView::copied_from_slice(b, &memory())
}
#[must_use]
pub fn to_bytes(v: BytesView) -> bytes::Bytes {
v.into()
}
pub fn io_slices<'a>(view: &'a BytesView, out: &mut [IoSlice<'a>]) -> usize {
bytes::Buf::chunks_vectored(view, out)
}