@@ -12,11 +12,11 @@ use crate::vm::VirtualMachine;
1212pub type PyGetterFunc = Box < dyn Fn ( & VirtualMachine , PyObjectRef ) -> PyResult > ;
1313pub type PySetterFunc = Box < dyn Fn ( & VirtualMachine , PyObjectRef , PyObjectRef ) -> PyResult < ( ) > > ;
1414
15- pub trait IntoPyGetterFunc < T , R > {
15+ pub trait IntoPyGetterFunc < T > {
1616 fn into_getter ( self ) -> PyGetterFunc ;
1717}
1818
19- impl < F , T , R > IntoPyGetterFunc < OwnedParam < T > , R > for F
19+ impl < F , T , R > IntoPyGetterFunc < ( OwnedParam < T > , R , VirtualMachine ) > for F
2020where
2121 F : Fn ( T , & VirtualMachine ) -> R + ' static ,
2222 T : TryFromObject ,
3030 }
3131}
3232
33- impl < F , S , R > IntoPyGetterFunc < RefParam < S > , R > for F
33+ impl < F , S , R > IntoPyGetterFunc < ( RefParam < S > , R , VirtualMachine ) > for F
3434where
3535 F : Fn ( & S , & VirtualMachine ) -> R + ' static ,
3636 S : PyValue ,
4444 }
4545}
4646
47+ impl < F , T , R > IntoPyGetterFunc < ( OwnedParam < T > , R ) > for F
48+ where
49+ F : Fn ( T ) -> R + ' static ,
50+ T : TryFromObject ,
51+ R : IntoPyObject ,
52+ {
53+ fn into_getter ( self ) -> PyGetterFunc {
54+ IntoPyGetterFunc :: into_getter ( move |obj, _vm : & VirtualMachine | ( self ) ( obj) )
55+ }
56+ }
57+
58+ impl < F , S , R > IntoPyGetterFunc < ( RefParam < S > , R ) > for F
59+ where
60+ F : Fn ( & S ) -> R + ' static ,
61+ S : PyValue ,
62+ R : IntoPyObject ,
63+ {
64+ fn into_getter ( self ) -> PyGetterFunc {
65+ IntoPyGetterFunc :: into_getter ( move |zelf : & S , _vm : & VirtualMachine | ( self ) ( zelf) )
66+ }
67+ }
68+
4769pub trait IntoPyNoResult {
4870 fn into_noresult ( self ) -> PyResult < ( ) > ;
4971}
@@ -60,14 +82,11 @@ impl IntoPyNoResult for PyResult<()> {
6082 }
6183}
6284
63- pub trait IntoPySetterFunc < T , V , R >
64- where
65- R : IntoPyNoResult ,
66- {
85+ pub trait IntoPySetterFunc < T > {
6786 fn into_setter ( self ) -> PySetterFunc ;
6887}
6988
70- impl < F , T , V , R > IntoPySetterFunc < OwnedParam < T > , V , R > for F
89+ impl < F , T , V , R > IntoPySetterFunc < ( OwnedParam < T > , V , R , VirtualMachine ) > for F
7190where
7291 F : Fn ( T , V , & VirtualMachine ) -> R + ' static ,
7392 T : TryFromObject ,
83102 }
84103}
85104
86- impl < F , S , V , R > IntoPySetterFunc < RefParam < S > , V , R > for F
105+ impl < F , S , V , R > IntoPySetterFunc < ( RefParam < S > , V , R , VirtualMachine ) > for F
87106where
88107 F : Fn ( & S , V , & VirtualMachine ) -> R + ' static ,
89108 S : PyValue ,
@@ -99,6 +118,30 @@ where
99118 }
100119}
101120
121+ impl < F , T , V , R > IntoPySetterFunc < ( OwnedParam < T > , V , R ) > for F
122+ where
123+ F : Fn ( T , V ) -> R + ' static ,
124+ T : TryFromObject ,
125+ V : TryFromObject ,
126+ R : IntoPyNoResult ,
127+ {
128+ fn into_setter ( self ) -> PySetterFunc {
129+ IntoPySetterFunc :: into_setter ( move |obj, v, _vm : & VirtualMachine | ( self ) ( obj, v) )
130+ }
131+ }
132+
133+ impl < F , S , V , R > IntoPySetterFunc < ( RefParam < S > , V , R ) > for F
134+ where
135+ F : Fn ( & S , V ) -> R + ' static ,
136+ S : PyValue ,
137+ V : TryFromObject ,
138+ R : IntoPyNoResult ,
139+ {
140+ fn into_setter ( self ) -> PySetterFunc {
141+ IntoPySetterFunc :: into_setter ( move |zelf : & S , v, _vm : & VirtualMachine | ( self ) ( zelf, v) )
142+ }
143+ }
144+
102145#[ pyclass]
103146pub struct PyGetSet {
104147 name : String ,
@@ -155,9 +198,9 @@ impl PyBuiltinDescriptor for PyGetSet {
155198}
156199
157200impl PyGetSet {
158- pub fn with_get < G , T , R > ( name : String , getter : G ) -> Self
201+ pub fn with_get < G , X > ( name : String , getter : G ) -> Self
159202 where
160- G : IntoPyGetterFunc < T , R > ,
203+ G : IntoPyGetterFunc < X > ,
161204 {
162205 Self {
163206 name,
@@ -166,11 +209,10 @@ impl PyGetSet {
166209 }
167210 }
168211
169- pub fn with_get_set < G , S , GT , GR , ST , SV , SR > ( name : String , getter : G , setter : S ) -> Self
212+ pub fn with_get_set < G , S , X , Y > ( name : String , getter : G , setter : S ) -> Self
170213 where
171- G : IntoPyGetterFunc < GT , GR > ,
172- S : IntoPySetterFunc < ST , SV , SR > ,
173- SR : IntoPyNoResult ,
214+ G : IntoPyGetterFunc < X > ,
215+ S : IntoPySetterFunc < Y > ,
174216 {
175217 Self {
176218 name,
0 commit comments