@@ -10,6 +10,10 @@ use std::sync::Mutex;
10
10
use std:: sync:: RwLock ;
11
11
12
12
use crate :: HasParamSpec ;
13
+ use crate :: IsA ;
14
+ use crate :: Object ;
15
+ use crate :: SendWeakRef ;
16
+ use crate :: WeakRef ;
13
17
14
18
// rustdoc-stripper-ignore-next
15
19
/// A type that can be used as a property. It covers every type which have an associated `ParamSpec`
@@ -50,6 +54,12 @@ impl<T: Property> Property for Rc<T> {
50
54
impl < T : Property > Property for Arc < T > {
51
55
type Value = T :: Value ;
52
56
}
57
+ impl < T : IsA < Object > + HasParamSpec > Property for WeakRef < T > {
58
+ type Value = Option < T > ;
59
+ }
60
+ impl < T : IsA < Object > + HasParamSpec > Property for SendWeakRef < T > {
61
+ type Value = Option < T > ;
62
+ }
53
63
54
64
// rustdoc-stripper-ignore-next
55
65
/// A container type implementing this trait can be read by the default getter generated by the `Props` macro.
@@ -169,6 +179,35 @@ impl<T> PropertySet for once_cell::unsync::OnceCell<T> {
169
179
}
170
180
}
171
181
182
+ impl < T : IsA < Object > > PropertyGet for WeakRef < T > {
183
+ type Value = Option < T > ;
184
+
185
+ fn get < R , F : Fn ( & Self :: Value ) -> R > ( & self , f : F ) -> R {
186
+ f ( & self . upgrade ( ) )
187
+ }
188
+ }
189
+ impl < T : IsA < Object > > PropertySet for WeakRef < T > {
190
+ type SetValue = Option < T > ;
191
+
192
+ fn set ( & self , v : Self :: SetValue ) {
193
+ self . set ( v. as_ref ( ) )
194
+ }
195
+ }
196
+ impl < T : IsA < Object > > PropertyGet for SendWeakRef < T > {
197
+ type Value = Option < T > ;
198
+
199
+ fn get < R , F : Fn ( & Self :: Value ) -> R > ( & self , f : F ) -> R {
200
+ f ( & self . upgrade ( ) )
201
+ }
202
+ }
203
+ impl < T : IsA < Object > > PropertySet for SendWeakRef < T > {
204
+ type SetValue = Option < T > ;
205
+
206
+ fn set ( & self , v : Self :: SetValue ) {
207
+ WeakRef :: set ( self , v. as_ref ( ) ) ;
208
+ }
209
+ }
210
+
172
211
// Smart pointers wrapping a `PropertyRead`/`PropertyWrite`
173
212
impl < T : PropertyGet > PropertyGet for Rc < T > {
174
213
type Value = T :: Value ;
0 commit comments