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

Method try_bytes_like

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

Source from the content-addressed store, hash-verified

14
15impl PyObject {
16 pub fn try_bytes_like<R>(
17 &self,
18 vm: &VirtualMachine,
19 f: impl FnOnce(&[u8]) -> R,
20 ) -> PyResult<R> {
21 let buffer = PyBuffer::try_from_borrowed_object(vm, self)?;
22 buffer
23 .as_contiguous()
24 .map(|x| f(&x))
25 .ok_or_else(|| vm.new_buffer_error("non-contiguous buffer is not a bytes-like object"))
26 }
27
28 pub fn try_rw_bytes_like<R>(
29 &self,

Callers 4

py_newMethod · 0.80
bytes_from_objectFunction · 0.80
cmpMethod · 0.80

Calls 4

ok_or_elseMethod · 0.80
fFunction · 0.50
mapMethod · 0.45
as_contiguousMethod · 0.45

Tested by

no test coverage detected