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

Method copy_to_slice_impl

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

Source from the content-addressed store, hash-verified

453 }
454
455 fn copy_to_slice_impl<T: Element + Copy>(
456 &self,
457 py: Python,
458 target: &mut [T],
459 fort: u8,
460 ) -> PyResult<()> {
461 if mem::size_of_val(target) != self.len_bytes() {
462 return slice_length_error(py);
463 }
464 if !T::is_compatible_format(self.format()) || mem::size_of::<T>() != self.item_size() {
465 return incompatible_format_error(py);
466 }
467 unsafe {
468 err::error_on_minusone(
469 py,
470 ffi::PyBuffer_ToContiguous(
471 target.as_ptr() as *mut libc::c_void,
472 &*self.0 as *const ffi::Py_buffer as *mut ffi::Py_buffer,
473 self.0.len,
474 fort as libc::c_char,
475 ),
476 )
477 }
478 }
479
480 /// Copies the buffer elements to a newly allocated vector.
481 /// If the buffer is multi-dimensional, the elements are written in C-style order.

Callers 2

copy_to_sliceMethod · 0.80
copy_to_fortran_sliceMethod · 0.80

Calls 7

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

Tested by

no test coverage detected