File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,8 @@ mod foo {
147
147
cell : Cell < u8 > ,
148
148
#[ property( get = Self :: overridden, override_class = Base ) ]
149
149
overridden : PhantomData < u32 > ,
150
+ #[ property( get, set) ]
151
+ weak_ref_prop : glib:: WeakRef < glib:: Object > ,
150
152
}
151
153
152
154
impl ObjectImpl for Foo {
Original file line number Diff line number Diff line change @@ -10,6 +10,9 @@ 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 :: WeakRef ;
13
16
14
17
// rustdoc-stripper-ignore-next
15
18
/// A type that can be used as a property. It covers every type which have an associated `ParamSpec`
@@ -50,6 +53,9 @@ impl<T: Property> Property for Rc<T> {
50
53
impl < T : Property > Property for Arc < T > {
51
54
type Value = T :: Value ;
52
55
}
56
+ impl < T : IsA < Object > + HasParamSpec > Property for WeakRef < T > {
57
+ type Value = Option < T > ;
58
+ }
53
59
54
60
// rustdoc-stripper-ignore-next
55
61
/// A container type implementing this trait can be read by the default getter generated by the `Props` macro.
@@ -169,6 +175,21 @@ impl<T> PropertySet for once_cell::unsync::OnceCell<T> {
169
175
}
170
176
}
171
177
178
+ impl < T : IsA < Object > > PropertyGet for WeakRef < T > {
179
+ type Value = Option < T > ;
180
+
181
+ fn get < R , F : Fn ( & Self :: Value ) -> R > ( & self , f : F ) -> R {
182
+ f ( & self . upgrade ( ) )
183
+ }
184
+ }
185
+ impl < T : IsA < Object > > PropertySet for WeakRef < T > {
186
+ type SetValue = Option < T > ;
187
+
188
+ fn set ( & self , v : Self :: SetValue ) {
189
+ self . set ( v. as_ref ( ) )
190
+ }
191
+ }
192
+
172
193
// Smart pointers wrapping a `PropertyRead`/`PropertyWrite`
173
194
impl < T : PropertyGet > PropertyGet for Rc < T > {
174
195
type Value = T :: Value ;
You can’t perform that action at this time.
0 commit comments