ps_buffer/methods/reserve_total.rs
1use crate::{Buffer, BufferError};
2
3impl Buffer {
4 /// - Ensures the are at least a total of `capacity` bytes reserved in this [`Buffer`].
5 /// - The current length of this [`Buffer`] is not taken into consideration.
6 /// - You might be looking for [`Buffer::reserve`].
7 /// # Errors
8 /// - `AllocationError` is returned if allocation fails.
9 /// - `DeallocationError` is returned if deallocation fails.
10 pub fn reserve_total(&mut self, capacity: usize) -> Result<&mut Self, BufferError> {
11 if capacity > self.capacity() {
12 self.realloc(capacity)?;
13 }
14
15 Ok(self)
16 }
17}