ps_buffer/methods/extend_with.rs
1use crate::{Buffer, BufferError};
2
3impl Buffer {
4 /// # Errors
5 /// - `AllocationError` is returned if allocation fails.
6 /// - `DeallocationError` is returned if deallocation fails.
7 pub fn extend_with(&mut self, n: usize, value: u8) -> Result<&mut Self, BufferError> {
8 if n == 0 {
9 return Ok(self);
10 }
11
12 self.reserve(n)?;
13
14 unsafe {
15 std::ptr::write_bytes(self.ptr.add(self.len()), value, n);
16 }
17
18 self.set_len(self.len() + n)
19 }
20}