@@ -44,36 +44,57 @@ where
44
44
}
45
45
}
46
46
47
- pub trait IntoPySetterFunc < T , V > {
47
+ pub trait IntoPyNoResult {
48
+ fn into_noresult ( self ) -> PyResult < ( ) > ;
49
+ }
50
+
51
+ impl IntoPyNoResult for ( ) {
52
+ fn into_noresult ( self ) -> PyResult < ( ) > {
53
+ Ok ( ( ) )
54
+ }
55
+ }
56
+
57
+ impl IntoPyNoResult for PyResult < ( ) > {
58
+ fn into_noresult ( self ) -> PyResult < ( ) > {
59
+ self
60
+ }
61
+ }
62
+
63
+ pub trait IntoPySetterFunc < T , V , R >
64
+ where
65
+ R : IntoPyNoResult ,
66
+ {
48
67
fn into_setter ( self ) -> PySetterFunc ;
49
68
}
50
69
51
- impl < F , T , V > IntoPySetterFunc < OwnedParam < T > , V > for F
70
+ impl < F , T , V , R > IntoPySetterFunc < OwnedParam < T > , V , R > for F
52
71
where
53
- F : Fn ( T , V , & VirtualMachine ) -> PyResult < ( ) > + ' static ,
72
+ F : Fn ( T , V , & VirtualMachine ) -> R + ' static ,
54
73
T : TryFromObject ,
55
74
V : TryFromObject ,
75
+ R : IntoPyNoResult ,
56
76
{
57
77
fn into_setter ( self ) -> PySetterFunc {
58
78
Box :: new ( move |vm, obj, value| {
59
79
let obj = T :: try_from_object ( vm, obj) ?;
60
80
let value = V :: try_from_object ( vm, value) ?;
61
- ( self ) ( obj, value, vm)
81
+ ( self ) ( obj, value, vm) . into_noresult ( )
62
82
} )
63
83
}
64
84
}
65
85
66
- impl < F , S , V > IntoPySetterFunc < RefParam < S > , V > for F
86
+ impl < F , S , V , R > IntoPySetterFunc < RefParam < S > , V , R > for F
67
87
where
68
- F : Fn ( & S , V , & VirtualMachine ) -> PyResult < ( ) > + ' static ,
88
+ F : Fn ( & S , V , & VirtualMachine ) -> R + ' static ,
69
89
S : PyValue ,
70
90
V : TryFromObject ,
91
+ R : IntoPyNoResult ,
71
92
{
72
93
fn into_setter ( self ) -> PySetterFunc {
73
94
Box :: new ( move |vm, obj, value| {
74
95
let zelf = PyRef :: < S > :: try_from_object ( vm, obj) ?;
75
96
let value = V :: try_from_object ( vm, value) ?;
76
- ( self ) ( & zelf, value, vm)
97
+ ( self ) ( & zelf, value, vm) . into_noresult ( )
77
98
} )
78
99
}
79
100
}
@@ -145,10 +166,11 @@ impl PyGetSet {
145
166
}
146
167
}
147
168
148
- pub fn with_get_set < G , S , GT , GR , ST , SV > ( name : String , getter : G , setter : S ) -> Self
169
+ pub fn with_get_set < G , S , GT , GR , ST , SV , SR > ( name : String , getter : G , setter : S ) -> Self
149
170
where
150
171
G : IntoPyGetterFunc < GT , GR > ,
151
- S : IntoPySetterFunc < ST , SV > ,
172
+ S : IntoPySetterFunc < ST , SV , SR > ,
173
+ SR : IntoPyNoResult ,
152
174
{
153
175
Self {
154
176
name,
0 commit comments