@@ -4,8 +4,8 @@ use std::ops::AddAssign;
4
4
use num_bigint:: BigInt ;
5
5
use num_traits:: Zero ;
6
6
7
- use crate :: function:: { OptionalArg , PyFuncArgs } ;
8
- use crate :: pyobject:: { PyContext , PyObjectRef , PyRef , PyResult , PyValue , TypeProtocol } ;
7
+ use crate :: function:: OptionalArg ;
8
+ use crate :: pyobject:: { PyContext , PyObjectRef , PyRef , PyResult , PyValue } ;
9
9
use crate :: vm:: VirtualMachine ;
10
10
11
11
use super :: objint:: PyIntRef ;
@@ -44,18 +44,10 @@ fn enumerate_new(
44
44
. into_ref_with_type ( vm, cls)
45
45
}
46
46
47
- fn enumerate_next ( vm : & VirtualMachine , args : PyFuncArgs ) -> PyResult {
48
- arg_check ! (
49
- vm,
50
- args,
51
- required = [ ( enumerate, Some ( vm. ctx. enumerate_type( ) ) ) ]
52
- ) ;
53
-
54
- if let Some ( PyEnumerate {
55
- ref counter,
56
- ref iterator,
57
- } ) = enumerate. payload ( )
58
- {
47
+ impl PyEnumerateRef {
48
+ fn next ( self , vm : & VirtualMachine ) -> PyResult {
49
+ let iterator = & self . iterator ;
50
+ let counter = & self . counter ;
59
51
let next_obj = objiter:: call_next ( vm, iterator) ?;
60
52
let result = vm
61
53
. ctx
@@ -64,8 +56,6 @@ fn enumerate_next(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
64
56
AddAssign :: add_assign ( & mut counter. borrow_mut ( ) as & mut BigInt , 1 ) ;
65
57
66
58
Ok ( result)
67
- } else {
68
- panic ! ( "enumerate doesn't have correct payload" ) ;
69
59
}
70
60
}
71
61
@@ -74,6 +64,6 @@ pub fn init(context: &PyContext) {
74
64
objiter:: iter_type_init ( context, enumerate_type) ;
75
65
extend_class ! ( context, enumerate_type, {
76
66
"__new__" => context. new_rustfunc( enumerate_new) ,
77
- "__next__" => context. new_rustfunc( enumerate_next )
67
+ "__next__" => context. new_rustfunc( PyEnumerateRef :: next )
78
68
} ) ;
79
69
}
0 commit comments