@@ -3,11 +3,26 @@ use std::ops::AddAssign;
33
44use super :: objint;
55use 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+ } ;
710use crate :: vm:: VirtualMachine ;
811use num_bigint:: BigInt ;
912use num_traits:: Zero ;
1013
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+
1126fn enumerate_new ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
1227 arg_check ! (
1328 vm,
@@ -22,9 +37,11 @@ fn enumerate_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
2237 } ;
2338 let iterator = objiter:: get_iter ( vm, iterable) ?;
2439 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+ } ) ,
2845 } ,
2946 cls. clone ( ) ,
3047 ) )
@@ -37,10 +54,10 @@ fn enumerate_next(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
3754 required = [ ( enumerate, Some ( vm. ctx. enumerate_type( ) ) ) ]
3855 ) ;
3956
40- if let PyObjectPayload :: EnumerateIterator {
57+ if let Some ( PyEnumerate {
4158 ref counter,
4259 ref iterator,
43- } = enumerate. payload
60+ } ) = enumerate. payload ( )
4461 {
4562 let next_obj = objiter:: call_next ( vm, iterator) ?;
4663 let result = vm
0 commit comments