@@ -452,9 +452,24 @@ impl PyContext {
452
452
)
453
453
}
454
454
455
- pub fn new_rustfunc ( & self , function : RustPyFunc ) -> PyObjectRef {
455
+ pub fn new_rustfunc < F : ' static + Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > (
456
+ & self ,
457
+ function : F ,
458
+ ) -> PyObjectRef {
456
459
PyObject :: new (
457
- PyObjectKind :: RustFunction { function : function } ,
460
+ PyObjectKind :: RustFunction {
461
+ function : Box :: new ( function) ,
462
+ } ,
463
+ self . function_type ( ) ,
464
+ )
465
+ }
466
+
467
+ pub fn new_rustfunc_from_box (
468
+ & self ,
469
+ function : Box < Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > ,
470
+ ) -> PyObjectRef {
471
+ PyObject :: new (
472
+ PyObjectKind :: RustFunction { function } ,
458
473
self . function_type ( ) ,
459
474
)
460
475
}
@@ -463,7 +478,10 @@ impl PyContext {
463
478
PyObject :: new ( PyObjectKind :: Frame { frame : frame } , self . frame_type ( ) )
464
479
}
465
480
466
- pub fn new_property ( & self , function : RustPyFunc ) -> PyObjectRef {
481
+ pub fn new_property < F : ' static + Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > (
482
+ & self ,
483
+ function : F ,
484
+ ) -> PyObjectRef {
467
485
let fget = self . new_rustfunc ( function) ;
468
486
let py_obj = PyObject :: new (
469
487
PyObjectKind :: Instance {
@@ -505,7 +523,10 @@ impl PyContext {
505
523
)
506
524
}
507
525
508
- pub fn new_member_descriptor ( & self , function : RustPyFunc ) -> PyObjectRef {
526
+ pub fn new_member_descriptor < F : ' static + Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > (
527
+ & self ,
528
+ function : F ,
529
+ ) -> PyObjectRef {
509
530
let dict = self . new_dict ( ) ;
510
531
self . set_item ( & dict, "function" , self . new_rustfunc ( function) ) ;
511
532
self . new_instance ( dict, self . member_descriptor_type ( ) )
@@ -772,8 +793,6 @@ impl PyFuncArgs {
772
793
}
773
794
}
774
795
775
- type RustPyFunc = fn ( vm : & mut VirtualMachine , PyFuncArgs ) -> PyResult ;
776
-
777
796
/// Rather than determining the type of a python object, this enum is more
778
797
/// a holder for the rust payload of a python object. It is more a carrier
779
798
/// of rust data for a particular python object. Determine the python type
@@ -850,7 +869,7 @@ pub enum PyObjectKind {
850
869
dict : PyObjectRef ,
851
870
} ,
852
871
RustFunction {
853
- function : RustPyFunc ,
872
+ function : Box < Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > ,
854
873
} ,
855
874
}
856
875
0 commit comments