@@ -465,9 +465,24 @@ impl PyContext {
465
465
)
466
466
}
467
467
468
- pub fn new_rustfunc ( & self , function : RustPyFunc ) -> PyObjectRef {
468
+ pub fn new_rustfunc < F : ' static + Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > (
469
+ & self ,
470
+ function : F ,
471
+ ) -> PyObjectRef {
469
472
PyObject :: new (
470
- PyObjectKind :: RustFunction { function : function } ,
473
+ PyObjectKind :: RustFunction {
474
+ function : Box :: new ( function) ,
475
+ } ,
476
+ self . function_type ( ) ,
477
+ )
478
+ }
479
+
480
+ pub fn new_rustfunc_from_box (
481
+ & self ,
482
+ function : Box < Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > ,
483
+ ) -> PyObjectRef {
484
+ PyObject :: new (
485
+ PyObjectKind :: RustFunction { function } ,
471
486
self . function_type ( ) ,
472
487
)
473
488
}
@@ -476,7 +491,10 @@ impl PyContext {
476
491
PyObject :: new ( PyObjectKind :: Frame { frame : frame } , self . frame_type ( ) )
477
492
}
478
493
479
- pub fn new_property ( & self , function : RustPyFunc ) -> PyObjectRef {
494
+ pub fn new_property < F : ' static + Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > (
495
+ & self ,
496
+ function : F ,
497
+ ) -> PyObjectRef {
480
498
let fget = self . new_rustfunc ( function) ;
481
499
let py_obj = PyObject :: new (
482
500
PyObjectKind :: Instance {
@@ -518,7 +536,10 @@ impl PyContext {
518
536
)
519
537
}
520
538
521
- pub fn new_member_descriptor ( & self , function : RustPyFunc ) -> PyObjectRef {
539
+ pub fn new_member_descriptor < F : ' static + Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > (
540
+ & self ,
541
+ function : F ,
542
+ ) -> PyObjectRef {
522
543
let dict = self . new_dict ( ) ;
523
544
self . set_item ( & dict, "function" , self . new_rustfunc ( function) ) ;
524
545
self . new_instance ( dict, self . member_descriptor_type ( ) )
@@ -791,8 +812,6 @@ impl PyFuncArgs {
791
812
}
792
813
}
793
814
794
- type RustPyFunc = fn ( vm : & mut VirtualMachine , PyFuncArgs ) -> PyResult ;
795
-
796
815
/// Rather than determining the type of a python object, this enum is more
797
816
/// a holder for the rust payload of a python object. It is more a carrier
798
817
/// of rust data for a particular python object. Determine the python type
@@ -869,7 +888,7 @@ pub enum PyObjectKind {
869
888
dict : PyObjectRef ,
870
889
} ,
871
890
RustFunction {
872
- function : RustPyFunc ,
891
+ function : Box < Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > ,
873
892
} ,
874
893
}
875
894
0 commit comments