@@ -3,11 +3,26 @@ use std::ops::AddAssign;
3
3
4
4
use super :: objint;
5
5
use super :: objiter;
6
- use crate :: pyobject:: { PyContext , PyFuncArgs , PyObject , PyObjectPayload , PyResult , TypeProtocol } ;
6
+ use crate :: pyobject:: {
7
+ PyContext , PyFuncArgs , PyObject , PyObjectPayload , PyObjectPayload2 , PyObjectRef , PyResult ,
8
+ TypeProtocol ,
9
+ } ;
7
10
use crate :: vm:: VirtualMachine ;
8
11
use num_bigint:: BigInt ;
9
12
use num_traits:: Zero ;
10
13
14
+ #[ derive( Debug ) ]
15
+ pub struct PyEnumerate {
16
+ counter : RefCell < BigInt > ,
17
+ iterator : PyObjectRef ,
18
+ }
19
+
20
+ impl PyObjectPayload2 for PyEnumerate {
21
+ fn required_type ( ctx : & PyContext ) -> PyObjectRef {
22
+ ctx. enumerate_type ( )
23
+ }
24
+ }
25
+
11
26
fn enumerate_new ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
12
27
arg_check ! (
13
28
vm,
@@ -22,9 +37,11 @@ fn enumerate_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
22
37
} ;
23
38
let iterator = objiter:: get_iter ( vm, iterable) ?;
24
39
Ok ( PyObject :: new (
25
- PyObjectPayload :: EnumerateIterator {
26
- counter : RefCell :: new ( counter) ,
27
- iterator,
40
+ PyObjectPayload :: AnyRustValue {
41
+ value : Box :: new ( PyEnumerate {
42
+ counter : RefCell :: new ( counter) ,
43
+ iterator,
44
+ } ) ,
28
45
} ,
29
46
cls. clone ( ) ,
30
47
) )
@@ -37,10 +54,10 @@ fn enumerate_next(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
37
54
required = [ ( enumerate, Some ( vm. ctx. enumerate_type( ) ) ) ]
38
55
) ;
39
56
40
- if let PyObjectPayload :: EnumerateIterator {
57
+ if let Some ( PyEnumerate {
41
58
ref counter,
42
59
ref iterator,
43
- } = enumerate. payload
60
+ } ) = enumerate. payload ( )
44
61
{
45
62
let next_obj = objiter:: call_next ( vm, iterator) ?;
46
63
let result = vm
0 commit comments