@@ -13,11 +13,11 @@ use crate::vm::VirtualMachine;
13
13
pub type PyGetterFunc = Box < dyn Fn ( PyObjectRef , & VirtualMachine ) -> PyResult > ;
14
14
pub type PySetterFunc = Box < dyn Fn ( PyObjectRef , PyObjectRef , & VirtualMachine ) -> PySetResult > ;
15
15
16
- pub trait IntoPyGetterFunc < T , R > {
16
+ pub trait IntoPyGetterFunc < T > {
17
17
fn into_getter ( self ) -> PyGetterFunc ;
18
18
}
19
19
20
- impl < F , T , R > IntoPyGetterFunc < OwnedParam < T > , R > for F
20
+ impl < F , T , R > IntoPyGetterFunc < ( OwnedParam < T > , R , VirtualMachine ) > for F
21
21
where
22
22
F : Fn ( T , & VirtualMachine ) -> R + ' static ,
23
23
T : TryFromObject ,
@@ -31,28 +31,47 @@ where
31
31
}
32
32
}
33
33
34
- impl < F , S , R > IntoPyGetterFunc < RefParam < S > , R > for F
34
+ impl < F , S , R > IntoPyGetterFunc < ( RefParam < S > , R , VirtualMachine ) > for F
35
35
where
36
36
F : Fn ( & S , & VirtualMachine ) -> R + ' static ,
37
37
S : PyValue ,
38
38
R : IntoPyObject ,
39
39
{
40
40
fn into_getter ( self ) -> PyGetterFunc {
41
41
Box :: new ( move |obj, vm| {
42
- let zelf = PyRef :: < S > :: try_from_object ( vm, obj) ?;
43
- ( self ) ( & zelf, vm) . into_pyobject ( vm)
42
+ let zelf = & PyRef :: < S > :: try_from_object ( vm, obj) ?;
43
+ ( self ) ( zelf, vm) . into_pyobject ( vm)
44
44
} )
45
45
}
46
46
}
47
47
48
- pub trait IntoPySetterFunc < T , V , R >
48
+ impl < F , T , R > IntoPyGetterFunc < ( OwnedParam < T > , R ) > for F
49
49
where
50
- R : IntoPySetResult ,
50
+ F : Fn ( T ) -> R + ' static ,
51
+ T : TryFromObject ,
52
+ R : IntoPyObject ,
51
53
{
54
+ fn into_getter ( self ) -> PyGetterFunc {
55
+ IntoPyGetterFunc :: into_getter ( move |obj, _vm : & VirtualMachine | ( self ) ( obj) )
56
+ }
57
+ }
58
+
59
+ impl < F , S , R > IntoPyGetterFunc < ( RefParam < S > , R ) > for F
60
+ where
61
+ F : Fn ( & S ) -> R + ' static ,
62
+ S : PyValue ,
63
+ R : IntoPyObject ,
64
+ {
65
+ fn into_getter ( self ) -> PyGetterFunc {
66
+ IntoPyGetterFunc :: into_getter ( move |zelf : & S , _vm : & VirtualMachine | ( self ) ( zelf) )
67
+ }
68
+ }
69
+
70
+ pub trait IntoPySetterFunc < T > {
52
71
fn into_setter ( self ) -> PySetterFunc ;
53
72
}
54
73
55
- impl < F , T , V , R > IntoPySetterFunc < OwnedParam < T > , V , R > for F
74
+ impl < F , T , V , R > IntoPySetterFunc < ( OwnedParam < T > , V , R , VirtualMachine ) > for F
56
75
where
57
76
F : Fn ( T , V , & VirtualMachine ) -> R + ' static ,
58
77
T : TryFromObject ,
68
87
}
69
88
}
70
89
71
- impl < F , S , V , R > IntoPySetterFunc < RefParam < S > , V , R > for F
90
+ impl < F , S , V , R > IntoPySetterFunc < ( RefParam < S > , V , R , VirtualMachine ) > for F
72
91
where
73
92
F : Fn ( & S , V , & VirtualMachine ) -> R + ' static ,
74
93
S : PyValue ,
@@ -84,6 +103,30 @@ where
84
103
}
85
104
}
86
105
106
+ impl < F , T , V , R > IntoPySetterFunc < ( OwnedParam < T > , V , R ) > for F
107
+ where
108
+ F : Fn ( T , V ) -> R + ' static ,
109
+ T : TryFromObject ,
110
+ V : TryFromObject ,
111
+ R : IntoPySetResult ,
112
+ {
113
+ fn into_setter ( self ) -> PySetterFunc {
114
+ IntoPySetterFunc :: into_setter ( move |obj, v, _vm : & VirtualMachine | ( self ) ( obj, v) )
115
+ }
116
+ }
117
+
118
+ impl < F , S , V , R > IntoPySetterFunc < ( RefParam < S > , V , R ) > for F
119
+ where
120
+ F : Fn ( & S , V ) -> R + ' static ,
121
+ S : PyValue ,
122
+ V : TryFromObject ,
123
+ R : IntoPySetResult ,
124
+ {
125
+ fn into_setter ( self ) -> PySetterFunc {
126
+ IntoPySetterFunc :: into_setter ( move |zelf : & S , v, _vm : & VirtualMachine | ( self ) ( zelf, v) )
127
+ }
128
+ }
129
+
87
130
#[ pyclass]
88
131
pub struct PyGetSet {
89
132
name : String ,
@@ -140,9 +183,9 @@ impl PyBuiltinDescriptor for PyGetSet {
140
183
}
141
184
142
185
impl PyGetSet {
143
- pub fn with_get < G , T , R > ( name : String , getter : G ) -> Self
186
+ pub fn with_get < G , X > ( name : String , getter : G ) -> Self
144
187
where
145
- G : IntoPyGetterFunc < T , R > ,
188
+ G : IntoPyGetterFunc < X > ,
146
189
{
147
190
Self {
148
191
name,
@@ -151,11 +194,10 @@ impl PyGetSet {
151
194
}
152
195
}
153
196
154
- pub fn with_get_set < G , S , GT , GR , ST , SV , SR > ( name : String , getter : G , setter : S ) -> Self
197
+ pub fn with_get_set < G , S , X , Y > ( name : String , getter : G , setter : S ) -> Self
155
198
where
156
- G : IntoPyGetterFunc < GT , GR > ,
157
- S : IntoPySetterFunc < ST , SV , SR > ,
158
- SR : IntoPySetResult ,
199
+ G : IntoPyGetterFunc < X > ,
200
+ S : IntoPySetterFunc < Y > ,
159
201
{
160
202
Self {
161
203
name,
0 commit comments