@@ -44,36 +44,57 @@ where
4444 }
4545}
4646
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+ {
4867 fn into_setter ( self ) -> PySetterFunc ;
4968}
5069
51- impl < F , T , V > IntoPySetterFunc < OwnedParam < T > , V > for F
70+ impl < F , T , V , R > IntoPySetterFunc < OwnedParam < T > , V , R > for F
5271where
53- F : Fn ( T , V , & VirtualMachine ) -> PyResult < ( ) > + ' static ,
72+ F : Fn ( T , V , & VirtualMachine ) -> R + ' static ,
5473 T : TryFromObject ,
5574 V : TryFromObject ,
75+ R : IntoPyNoResult ,
5676{
5777 fn into_setter ( self ) -> PySetterFunc {
5878 Box :: new ( move |vm, obj, value| {
5979 let obj = T :: try_from_object ( vm, obj) ?;
6080 let value = V :: try_from_object ( vm, value) ?;
61- ( self ) ( obj, value, vm)
81+ ( self ) ( obj, value, vm) . into_noresult ( )
6282 } )
6383 }
6484}
6585
66- impl < F , S , V > IntoPySetterFunc < RefParam < S > , V > for F
86+ impl < F , S , V , R > IntoPySetterFunc < RefParam < S > , V , R > for F
6787where
68- F : Fn ( & S , V , & VirtualMachine ) -> PyResult < ( ) > + ' static ,
88+ F : Fn ( & S , V , & VirtualMachine ) -> R + ' static ,
6989 S : PyValue ,
7090 V : TryFromObject ,
91+ R : IntoPyNoResult ,
7192{
7293 fn into_setter ( self ) -> PySetterFunc {
7394 Box :: new ( move |vm, obj, value| {
7495 let zelf = PyRef :: < S > :: try_from_object ( vm, obj) ?;
7596 let value = V :: try_from_object ( vm, value) ?;
76- ( self ) ( & zelf, value, vm)
97+ ( self ) ( & zelf, value, vm) . into_noresult ( )
7798 } )
7899 }
79100}
@@ -145,10 +166,11 @@ impl PyGetSet {
145166 }
146167 }
147168
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
149170 where
150171 G : IntoPyGetterFunc < GT , GR > ,
151- S : IntoPySetterFunc < ST , SV > ,
172+ S : IntoPySetterFunc < ST , SV , SR > ,
173+ SR : IntoPyNoResult ,
152174 {
153175 Self {
154176 name,
0 commit comments