2
2
3
3
*/
4
4
use super :: objtype:: PyClassRef ;
5
- use crate :: function:: OptionalArg ;
5
+ use crate :: function:: { OptionalArg , OwnedParam , RefParam } ;
6
6
use crate :: pyobject:: {
7
7
IntoPyObject , PyClassImpl , PyContext , PyObjectRef , PyRef , PyResult , PyValue , TryFromObject ,
8
8
} ;
@@ -16,7 +16,7 @@ pub trait IntoPyGetterFunc<T, R> {
16
16
fn into_getter ( self ) -> PyGetterFunc ;
17
17
}
18
18
19
- impl < F , T , R > IntoPyGetterFunc < T , R > for F
19
+ impl < F , T , R > IntoPyGetterFunc < OwnedParam < T > , R > for F
20
20
where
21
21
F : Fn ( T , & VirtualMachine ) -> R + ' static ,
22
22
T : TryFromObject ,
@@ -30,11 +30,25 @@ where
30
30
}
31
31
}
32
32
33
+ impl < F , S , R > IntoPyGetterFunc < RefParam < S > , R > for F
34
+ where
35
+ F : Fn ( & S , & VirtualMachine ) -> R + ' static ,
36
+ S : PyValue ,
37
+ R : IntoPyObject ,
38
+ {
39
+ fn into_getter ( self ) -> PyGetterFunc {
40
+ Box :: new ( move |vm, obj| {
41
+ let zelf = PyRef :: < S > :: try_from_object ( vm, obj) ?;
42
+ ( self ) ( & zelf, vm) . into_pyobject ( vm)
43
+ } )
44
+ }
45
+ }
46
+
33
47
pub trait IntoPySetterFunc < T , V > {
34
48
fn into_setter ( self ) -> PySetterFunc ;
35
49
}
36
50
37
- impl < F , T , V > IntoPySetterFunc < T , V > for F
51
+ impl < F , T , V > IntoPySetterFunc < OwnedParam < T > , V > for F
38
52
where
39
53
F : Fn ( T , V , & VirtualMachine ) -> PyResult < ( ) > + ' static ,
40
54
T : TryFromObject ,
49
63
}
50
64
}
51
65
66
+ impl < F , S , V > IntoPySetterFunc < RefParam < S > , V > for F
67
+ where
68
+ F : Fn ( & S , V , & VirtualMachine ) -> PyResult < ( ) > + ' static ,
69
+ S : PyValue ,
70
+ V : TryFromObject ,
71
+ {
72
+ fn into_setter ( self ) -> PySetterFunc {
73
+ Box :: new ( move |vm, obj, value| {
74
+ let zelf = PyRef :: < S > :: try_from_object ( vm, obj) ?;
75
+ let value = V :: try_from_object ( vm, value) ?;
76
+ ( self ) ( & zelf, value, vm)
77
+ } )
78
+ }
79
+ }
80
+
52
81
#[ pyclass]
53
82
pub struct PyGetSet {
54
83
name : String ,
0 commit comments