MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / copy_from_slice_impl

Method copy_from_slice_impl

src/buffer.rs:553–579  ·  view source on GitHub ↗
(
        &self,
        py: Python,
        source: &[T],
        fort: u8,
    )

Source from the content-addressed store, hash-verified

551 }
552
553 fn copy_from_slice_impl<T: Element + Copy>(
554 &self,
555 py: Python,
556 source: &[T],
557 fort: u8,
558 ) -> PyResult<()> {
559 if self.readonly() {
560 return buffer_readonly_error(py);
561 }
562 if mem::size_of_val(source) != self.len_bytes() {
563 return slice_length_error(py);
564 }
565 if !T::is_compatible_format(self.format()) || mem::size_of::<T>() != self.item_size() {
566 return incompatible_format_error(py);
567 }
568 unsafe {
569 err::error_on_minusone(
570 py,
571 ffi::PyBuffer_FromContiguous(
572 &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer,
573 source.as_ptr() as *mut libc::c_void,
574 self.0.len,
575 fort as libc::c_char,
576 ),
577 )
578 }
579 }
580}
581
582fn slice_length_error(py: Python) -> PyResult<()> {

Callers 2

copy_from_sliceMethod · 0.80

Calls 9

buffer_readonly_errorFunction · 0.85
slice_length_errorFunction · 0.85
error_on_minusoneFunction · 0.85
readonlyMethod · 0.80
len_bytesMethod · 0.80
formatMethod · 0.80
item_sizeMethod · 0.80
as_ptrMethod · 0.45

Tested by

no test coverage detected