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

Method try_rw_bytes_like

crates/vm/src/function/buffer.rs:28–38  ·  view source on GitHub ↗
(
        &self,
        vm: &VirtualMachine,
        f: impl FnOnce(&mut [u8]) -> R,
    )

Source from the content-addressed store, hash-verified

26 }
27
28 pub fn try_rw_bytes_like<R>(
29 &self,
30 vm: &VirtualMachine,
31 f: impl FnOnce(&mut [u8]) -> R,
32 ) -> PyResult<R> {
33 let buffer = PyBuffer::try_from_borrowed_object(vm, self)?;
34 buffer
35 .as_contiguous_mut()
36 .map(|mut x| f(&mut x))
37 .ok_or_else(|| vm.new_type_error("buffer is not a read-write bytes-like object"))
38 }
39}
40
41impl ArgBytesLike {

Callers

nothing calls this directly

Calls 4

ok_or_elseMethod · 0.80
as_contiguous_mutMethod · 0.80
fFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected