1
+ use crate :: pyobject:: {
2
+ PyContext , PyFuncArgs , PyObject , PyObjectPayload , PyObjectPayload2 , PyObjectRef , PyResult ,
3
+ TypeProtocol ,
4
+ } ;
5
+ use crate :: vm:: VirtualMachine ;
6
+
1
7
use super :: objiter;
2
- use crate :: pyobject:: { PyContext , PyFuncArgs , PyObject , PyObjectPayload , PyResult , TypeProtocol } ;
3
- use crate :: vm:: VirtualMachine ; // Required for arg_check! to use isinstance
8
+
9
+ #[ derive( Debug ) ]
10
+ pub struct PyMap {
11
+ mapper : PyObjectRef ,
12
+ iterators : Vec < PyObjectRef > ,
13
+ }
14
+
15
+ impl PyObjectPayload2 for PyMap {
16
+ fn required_type ( ctx : & PyContext ) -> PyObjectRef {
17
+ ctx. map_type ( )
18
+ }
19
+ }
4
20
5
21
fn map_new ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
6
22
no_kwargs ! ( vm, args) ;
@@ -15,9 +31,11 @@ fn map_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
15
31
. map ( |iterable| objiter:: get_iter ( vm, iterable) )
16
32
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
17
33
Ok ( PyObject :: new (
18
- PyObjectPayload :: MapIterator {
19
- mapper : function. clone ( ) ,
20
- iterators,
34
+ PyObjectPayload :: AnyRustValue {
35
+ value : Box :: new ( PyMap {
36
+ mapper : function. clone ( ) ,
37
+ iterators,
38
+ } ) ,
21
39
} ,
22
40
cls. clone ( ) ,
23
41
) )
@@ -27,10 +45,10 @@ fn map_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
27
45
fn map_next ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
28
46
arg_check ! ( vm, args, required = [ ( map, Some ( vm. ctx. map_type( ) ) ) ] ) ;
29
47
30
- if let PyObjectPayload :: MapIterator {
48
+ if let Some ( PyMap {
31
49
ref mapper,
32
50
ref iterators,
33
- } = map. payload
51
+ } ) = map. payload :: < PyMap > ( )
34
52
{
35
53
let next_objs = iterators
36
54
. iter ( )
0 commit comments