ps_buffer/methods/
set_len.rs

1use crate::{Buffer, BufferError};
2
3impl Buffer {
4    /// Modifies the length of this buffer **without initialization**.
5    /// # Errors
6    /// - `AllocationError` is returned if allocation fails.
7    /// - `DeallocationError` is returned if deallocation fails.
8    pub fn set_len(&mut self, new_len: usize) -> Result<&mut Self, BufferError> {
9        if new_len > self.capacity() {
10            self.realloc(new_len)?;
11        }
12
13        self.length = new_len;
14
15        Ok(self)
16    }
17}