(
&self,
vm: &VirtualMachine,
f: impl FnOnce(&[u8]) -> R,
)
| 14 | |
| 15 | impl 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, |
no test coverage detected