@@ -452,9 +452,24 @@ impl PyContext {
452452 )
453453 }
454454
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 {
456459 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 } ,
458473 self . function_type ( ) ,
459474 )
460475 }
@@ -463,7 +478,10 @@ impl PyContext {
463478 PyObject :: new ( PyObjectKind :: Frame { frame : frame } , self . frame_type ( ) )
464479 }
465480
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 {
467485 let fget = self . new_rustfunc ( function) ;
468486 let py_obj = PyObject :: new (
469487 PyObjectKind :: Instance {
@@ -505,7 +523,10 @@ impl PyContext {
505523 )
506524 }
507525
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 {
509530 let dict = self . new_dict ( ) ;
510531 self . set_item ( & dict, "function" , self . new_rustfunc ( function) ) ;
511532 self . new_instance ( dict, self . member_descriptor_type ( ) )
@@ -772,8 +793,6 @@ impl PyFuncArgs {
772793 }
773794}
774795
775- type RustPyFunc = fn ( vm : & mut VirtualMachine , PyFuncArgs ) -> PyResult ;
776-
777796/// Rather than determining the type of a python object, this enum is more
778797/// a holder for the rust payload of a python object. It is more a carrier
779798/// of rust data for a particular python object. Determine the python type
@@ -850,7 +869,7 @@ pub enum PyObjectKind {
850869 dict : PyObjectRef ,
851870 } ,
852871 RustFunction {
853- function : RustPyFunc ,
872+ function : Box < Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > ,
854873 } ,
855874}
856875
0 commit comments