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

Method set_state

crates/vm/src/builtins/iter.rs:54–69  ·  view source on GitHub ↗
(&mut self, state: PyObjectRef, f: F, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

52 }
53
54 pub fn set_state<F>(&mut self, state: PyObjectRef, f: F, vm: &VirtualMachine) -> PyResult<()>
55 where
56 F: FnOnce(&T, usize) -> usize,
57 {
58 if let IterStatus::Active(obj) = &self.status {
59 if let Some(i) = state.downcast_ref::<PyInt>() {
60 let i = i.try_to_primitive(vm).unwrap_or(0);
61 self.position = f(obj, i);
62 Ok(())
63 } else {
64 Err(vm.new_type_error("an integer is required."))
65 }
66 } else {
67 Ok(())
68 }
69 }
70
71 /// Build a pickle-compatible reduce tuple.
72 ///

Callers 9

setstateMethod · 0.80
__setstate__Method · 0.80
__setstate__Method · 0.80
__setstate__Method · 0.80
__setstate__Method · 0.80
__setstate__Method · 0.80
__setstate__Method · 0.80
__setstate__Method · 0.80
__setstate__Method · 0.80

Calls 3

try_to_primitiveMethod · 0.80
fFunction · 0.50
ErrClass · 0.50

Tested by

no test coverage detected