(&mut self, state: PyObjectRef, f: F, vm: &VirtualMachine)
| 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 | /// |
no test coverage detected