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

Function bytes_from_object

crates/vm/src/byte.rs:6–18  ·  view source on GitHub ↗
(vm: &VirtualMachine, obj: &PyObject)

Source from the content-addressed store, hash-verified

4use num_traits::ToPrimitive;
5
6pub fn bytes_from_object(vm: &VirtualMachine, obj: &PyObject) -> PyResult<Vec<u8>> {
7 if let Ok(elements) = obj.try_bytes_like(vm, |bytes| bytes.to_vec()) {
8 return Ok(elements);
9 }
10
11 if !obj.fast_isinstance(vm.ctx.types.str_type)
12 && let Ok(elements) = vm.map_iterable_object(obj, |x| value_from_object(vm, &x))
13 {
14 return elements;
15 }
16
17 Err(vm.new_type_error("can assign only bytes, buffers, or iterables of ints in range(0, 256)"))
18}
19
20pub fn value_from_object(vm: &VirtualMachine, obj: &PyObject) -> PyResult<u8> {
21 obj.try_index(vm)?

Callers 5

setitem_by_sliceMethod · 0.85
get_value_from_sourceMethod · 0.85
_setitemMethod · 0.85
extendMethod · 0.85

Calls 6

value_from_objectFunction · 0.85
try_bytes_likeMethod · 0.80
to_vecMethod · 0.80
fast_isinstanceMethod · 0.80
map_iterable_objectMethod · 0.80
ErrClass · 0.50

Tested by

no test coverage detected