22
33*/
44use super :: objtype:: PyClassRef ;
5- use crate :: function:: OptionalArg ;
5+ use crate :: function:: { OptionalArg , OwnedParam , RefParam } ;
66use crate :: pyobject:: {
77 IntoPyObject , PyClassImpl , PyContext , PyObjectRef , PyRef , PyResult , PyValue , TryFromObject ,
88} ;
@@ -16,7 +16,7 @@ pub trait IntoPyGetterFunc<T, R> {
1616 fn into_getter ( self ) -> PyGetterFunc ;
1717}
1818
19- impl < F , T , R > IntoPyGetterFunc < T , R > for F
19+ impl < F , T , R > IntoPyGetterFunc < OwnedParam < T > , R > for F
2020where
2121 F : Fn ( T , & VirtualMachine ) -> R + ' static ,
2222 T : TryFromObject ,
@@ -30,11 +30,25 @@ where
3030 }
3131}
3232
33+ impl < F , S , R > IntoPyGetterFunc < RefParam < S > , R > for F
34+ where
35+ F : Fn ( & S , & VirtualMachine ) -> R + ' static ,
36+ S : PyValue ,
37+ R : IntoPyObject ,
38+ {
39+ fn into_getter ( self ) -> PyGetterFunc {
40+ Box :: new ( move |vm, obj| {
41+ let zelf = PyRef :: < S > :: try_from_object ( vm, obj) ?;
42+ ( self ) ( & zelf, vm) . into_pyobject ( vm)
43+ } )
44+ }
45+ }
46+
3347pub trait IntoPySetterFunc < T , V > {
3448 fn into_setter ( self ) -> PySetterFunc ;
3549}
3650
37- impl < F , T , V > IntoPySetterFunc < T , V > for F
51+ impl < F , T , V > IntoPySetterFunc < OwnedParam < T > , V > for F
3852where
3953 F : Fn ( T , V , & VirtualMachine ) -> PyResult < ( ) > + ' static ,
4054 T : TryFromObject ,
4963 }
5064}
5165
66+ impl < F , S , V > IntoPySetterFunc < RefParam < S > , V > for F
67+ where
68+ F : Fn ( & S , V , & VirtualMachine ) -> PyResult < ( ) > + ' static ,
69+ S : PyValue ,
70+ V : TryFromObject ,
71+ {
72+ fn into_setter ( self ) -> PySetterFunc {
73+ Box :: new ( move |vm, obj, value| {
74+ let zelf = PyRef :: < S > :: try_from_object ( vm, obj) ?;
75+ let value = V :: try_from_object ( vm, value) ?;
76+ ( self ) ( & zelf, value, vm)
77+ } )
78+ }
79+ }
80+
5281#[ pyclass]
5382pub struct PyGetSet {
5483 name : String ,
0 commit comments