added utility function

This commit is contained in:
Monica Moniot
2023-12-05 10:52:26 -05:00
parent 27e43ff68b
commit 16195bb587
+10
View File
@@ -47,6 +47,11 @@ impl Buf {
Self(NonNull::new_unchecked(b))
}
}
pub fn create_from(buffer: &[u8]) -> Buf {
let mut buf = Self::new(buffer.len());
let _ = buf.append(buffer);
buf
}
#[inline(always)]
pub fn iter(&self) -> impl Iterator<Item = &u8> {
@@ -370,6 +375,11 @@ impl Pool {
}
}
}
pub fn create_from(&self, buffer: &[u8]) -> Buf {
let mut buf = self.get_with_min_capacity(buffer.len());
let _ = buf.append(buffer);
buf
}
/// Get a buffer from the pool or direct allocation if min_capacity is larger than pool buffer capacity.
#[inline]