ps_buffer/methods/extend_from_slice.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_from_slice<T>(&mut self, other: T) -> Result<&mut Self, BufferError>
8 where
9 T: AsRef<[u8]>,
10 {
11 let other = other.as_ref();
12
13 if other.is_empty() {
14 return Ok(self);
15 }
16
17 self.reserve(other.len())?;
18
19 unsafe {
20 std::ptr::copy_nonoverlapping(other.as_ptr(), self.ptr.add(self.len()), other.len());
21 }
22
23 self.set_len(self.len() + other.len())
24 }
25}