@@ -12,11 +12,11 @@ use crate::vm::VirtualMachine;
12
12
pub type PyGetterFunc = Box < dyn Fn ( & VirtualMachine , PyObjectRef ) -> PyResult > ;
13
13
pub type PySetterFunc = Box < dyn Fn ( & VirtualMachine , PyObjectRef , PyObjectRef ) -> PyResult < ( ) > > ;
14
14
15
- pub trait IntoPyGetterFunc < T , R > {
15
+ pub trait IntoPyGetterFunc < T > {
16
16
fn into_getter ( self ) -> PyGetterFunc ;
17
17
}
18
18
19
- impl < F , T , R > IntoPyGetterFunc < OwnedParam < T > , R > for F
19
+ impl < F , T , R > IntoPyGetterFunc < ( OwnedParam < T > , R , VirtualMachine ) > for F
20
20
where
21
21
F : Fn ( T , & VirtualMachine ) -> R + ' static ,
22
22
T : TryFromObject ,
30
30
}
31
31
}
32
32
33
- impl < F , S , R > IntoPyGetterFunc < RefParam < S > , R > for F
33
+ impl < F , S , R > IntoPyGetterFunc < ( RefParam < S > , R , VirtualMachine ) > for F
34
34
where
35
35
F : Fn ( & S , & VirtualMachine ) -> R + ' static ,
36
36
S : PyValue ,
44
44
}
45
45
}
46
46
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
+
47
69
pub trait IntoPyNoResult {
48
70
fn into_noresult ( self ) -> PyResult < ( ) > ;
49
71
}
@@ -60,14 +82,11 @@ impl IntoPyNoResult for PyResult<()> {
60
82
}
61
83
}
62
84
63
- pub trait IntoPySetterFunc < T , V , R >
64
- where
65
- R : IntoPyNoResult ,
66
- {
85
+ pub trait IntoPySetterFunc < T > {
67
86
fn into_setter ( self ) -> PySetterFunc ;
68
87
}
69
88
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
71
90
where
72
91
F : Fn ( T , V , & VirtualMachine ) -> R + ' static ,
73
92
T : TryFromObject ,
83
102
}
84
103
}
85
104
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
87
106
where
88
107
F : Fn ( & S , V , & VirtualMachine ) -> R + ' static ,
89
108
S : PyValue ,
@@ -99,6 +118,30 @@ where
99
118
}
100
119
}
101
120
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
+
102
145
#[ pyclass]
103
146
pub struct PyGetSet {
104
147
name : String ,
@@ -155,9 +198,9 @@ impl PyBuiltinDescriptor for PyGetSet {
155
198
}
156
199
157
200
impl 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
159
202
where
160
- G : IntoPyGetterFunc < T , R > ,
203
+ G : IntoPyGetterFunc < X > ,
161
204
{
162
205
Self {
163
206
name,
@@ -166,11 +209,10 @@ impl PyGetSet {
166
209
}
167
210
}
168
211
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
170
213
where
171
- G : IntoPyGetterFunc < GT , GR > ,
172
- S : IntoPySetterFunc < ST , SV , SR > ,
173
- SR : IntoPyNoResult ,
214
+ G : IntoPyGetterFunc < X > ,
215
+ S : IntoPySetterFunc < Y > ,
174
216
{
175
217
Self {
176
218
name,
0 commit comments