MCPcopy Index your code
hub / github.com/RustPython/RustPython / try_extend_from_slice

Method try_extend_from_slice

crates/common/src/boxvec.rs:238–255  ·  view source on GitHub ↗

Copy and appends all elements in a slice to the `BoxVec`. # Errors This method will return an error if the capacity left (see [`remaining_capacity`]) is smaller then the length of the provided slice. [`remaining_capacity`]: #method.remaining_capacity

(&mut self, other: &[T])

Source from the content-addressed store, hash-verified

236 ///
237 /// [`remaining_capacity`]: #method.remaining_capacity
238 pub fn try_extend_from_slice(&mut self, other: &[T]) -> Result<(), CapacityError>
239 where
240 T: Copy,
241 {
242 if self.remaining_capacity() < other.len() {
243 return Err(CapacityError::new(()));
244 }
245
246 let self_len = self.len();
247 let other_len = other.len();
248
249 unsafe {
250 let dst = self.as_mut_ptr().add(self_len);
251 ptr::copy_nonoverlapping(other.as_ptr(), dst, other_len);
252 self.set_len(self_len + other_len);
253 }
254 Ok(())
255 }
256
257 /// Create a draining iterator that removes the specified range in the vector
258 /// and yields the removed items from start to end. The element range is

Callers

nothing calls this directly

Calls 8

newFunction · 0.85
remaining_capacityMethod · 0.80
as_mut_ptrMethod · 0.80
set_lenMethod · 0.80
ErrClass · 0.50
lenMethod · 0.45
addMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected