diff --git a/src/buf.rs b/src/buf.rs index 7a1be5a..24b4c59 100644 --- a/src/buf.rs +++ b/src/buf.rs @@ -298,6 +298,16 @@ impl Pool { } } } + + /// Get a buffer from the pool or direct allocation if min_capacity is larger than pool buffer capacity. + #[inline] + pub fn get_with_min_capacity(&self, min_capacity: usize) -> Buf { + if unsafe { (*self.0).buf_capacity } >= min_capacity { + self.get() + } else { + Buf::new(min_capacity) + } + } } impl Drop for Pool {