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

Method fromhex_object

crates/vm/src/bytes_inner.rs:485–499  ·  view source on GitHub ↗

Parse hex string from str or bytes-like object

(string: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

483
484 /// Parse hex string from str or bytes-like object
485 pub fn fromhex_object(string: PyObjectRef, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
486 if let Some(s) = string.downcast_ref::<PyStr>() {
487 Self::fromhex(s.as_bytes(), vm)
488 } else if let Ok(buffer) = PyBuffer::try_from_borrowed_object(vm, &string) {
489 let borrowed = buffer
490 .as_contiguous()
491 .ok_or_else(|| vm.new_buffer_error("fromhex() requires a contiguous buffer"))?;
492 Self::fromhex(&borrowed, vm)
493 } else {
494 Err(vm.new_type_error(format!(
495 "fromhex() argument must be str or bytes-like, not {}",
496 string.class().name()
497 )))
498 }
499 }
500
501 #[inline]
502 fn _pad(

Callers

nothing calls this directly

Calls 4

ok_or_elseMethod · 0.80
ErrClass · 0.50
as_bytesMethod · 0.45
as_contiguousMethod · 0.45

Tested by

no test coverage detected