@@ -465,9 +465,24 @@ impl PyContext {
465465 )
466466 }
467467
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 {
469472 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 } ,
471486 self . function_type ( ) ,
472487 )
473488 }
@@ -476,7 +491,10 @@ impl PyContext {
476491 PyObject :: new ( PyObjectKind :: Frame { frame : frame } , self . frame_type ( ) )
477492 }
478493
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 {
480498 let fget = self . new_rustfunc ( function) ;
481499 let py_obj = PyObject :: new (
482500 PyObjectKind :: Instance {
@@ -518,7 +536,10 @@ impl PyContext {
518536 )
519537 }
520538
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 {
522543 let dict = self . new_dict ( ) ;
523544 self . set_item ( & dict, "function" , self . new_rustfunc ( function) ) ;
524545 self . new_instance ( dict, self . member_descriptor_type ( ) )
@@ -791,8 +812,6 @@ impl PyFuncArgs {
791812 }
792813}
793814
794- type RustPyFunc = fn ( vm : & mut VirtualMachine , PyFuncArgs ) -> PyResult ;
795-
796815/// Rather than determining the type of a python object, this enum is more
797816/// a holder for the rust payload of a python object. It is more a carrier
798817/// of rust data for a particular python object. Determine the python type
@@ -869,7 +888,7 @@ pub enum PyObjectKind {
869888 dict : PyObjectRef ,
870889 } ,
871890 RustFunction {
872- function : RustPyFunc ,
891+ function : Box < Fn ( & mut VirtualMachine , PyFuncArgs ) -> PyResult > ,
873892 } ,
874893}
875894
0 commit comments