@@ -598,16 +598,18 @@ impl FromGlibPtrArrayContainerAsVec<*mut GObject, *const *mut GObject> for Objec
598
598
}
599
599
600
600
#[ repr( transparent) ]
601
- pub struct TypedObjectRef < T > {
601
+ pub struct TypedObjectRef < T , P > {
602
602
inner : ObjectRef ,
603
- phantom : PhantomData < T > ,
603
+ imp : PhantomData < T > ,
604
+ parent : PhantomData < P > ,
604
605
}
605
606
606
- impl < T > TypedObjectRef < T > {
607
+ impl < T , P > TypedObjectRef < T , P > {
607
608
pub unsafe fn new ( obj : ObjectRef ) -> Self {
608
609
Self {
609
610
inner : obj,
610
- phantom : PhantomData ,
611
+ imp : PhantomData ,
612
+ parent : PhantomData ,
611
613
}
612
614
}
613
615
@@ -616,24 +618,25 @@ impl<T> TypedObjectRef<T> {
616
618
}
617
619
}
618
620
619
- impl < T > Clone for TypedObjectRef < T > {
621
+ impl < T , P > Clone for TypedObjectRef < T , P > {
620
622
fn clone ( & self ) -> Self {
621
623
Self {
622
624
inner : self . inner . clone ( ) ,
623
- phantom : PhantomData ,
625
+ imp : PhantomData ,
626
+ parent : PhantomData ,
624
627
}
625
628
}
626
629
}
627
630
628
- impl < T > ops:: Deref for TypedObjectRef < T > {
631
+ impl < T , P > ops:: Deref for TypedObjectRef < T , P > {
629
632
type Target = ObjectRef ;
630
633
631
634
fn deref ( & self ) -> & Self :: Target {
632
635
& self . inner
633
636
}
634
637
}
635
638
636
- impl < T > fmt:: Debug for TypedObjectRef < T > {
639
+ impl < T , P > fmt:: Debug for TypedObjectRef < T , P > {
637
640
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
638
641
let type_ = unsafe {
639
642
let klass = ( * self . inner . inner . as_ptr ( ) ) . g_type_instance . g_class as * const ObjectClass ;
@@ -647,27 +650,27 @@ impl<T> fmt::Debug for TypedObjectRef<T> {
647
650
}
648
651
}
649
652
650
- impl < T > PartialOrd for TypedObjectRef < T > {
653
+ impl < T , P > PartialOrd for TypedObjectRef < T , P > {
651
654
fn partial_cmp ( & self , other : & Self ) -> Option < cmp:: Ordering > {
652
655
self . inner . partial_cmp ( & other. inner )
653
656
}
654
657
}
655
658
656
- impl < T > Ord for TypedObjectRef < T > {
659
+ impl < T , P > Ord for TypedObjectRef < T , P > {
657
660
fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
658
661
self . inner . cmp ( & other. inner )
659
662
}
660
663
}
661
664
662
- impl < T > PartialEq for TypedObjectRef < T > {
665
+ impl < T , P > PartialEq for TypedObjectRef < T , P > {
663
666
fn eq ( & self , other : & Self ) -> bool {
664
667
self . inner == other. inner
665
668
}
666
669
}
667
670
668
- impl < T > Eq for TypedObjectRef < T > { }
671
+ impl < T , P > Eq for TypedObjectRef < T , P > { }
669
672
670
- impl < T > hash:: Hash for TypedObjectRef < T > {
673
+ impl < T , P > hash:: Hash for TypedObjectRef < T , P > {
671
674
fn hash < H > ( & self , state : & mut H )
672
675
where
673
676
H : hash:: Hasher ,
@@ -676,18 +679,18 @@ impl<T> hash::Hash for TypedObjectRef<T> {
676
679
}
677
680
}
678
681
679
- unsafe impl < T : Send + Sync > Send for TypedObjectRef < T > { }
680
- unsafe impl < T : Send + Sync > Sync for TypedObjectRef < T > { }
682
+ unsafe impl < T : Send + Sync , P : Send + Sync > Send for TypedObjectRef < T , P > { }
683
+ unsafe impl < T : Send + Sync , P : Send + Sync > Sync for TypedObjectRef < T , P > { }
681
684
682
685
// rustdoc-stripper-ignore-next
683
686
/// ObjectType implementations for Object types. See `wrapper!`.
684
687
#[ macro_export]
685
688
macro_rules! glib_object_wrapper {
686
- ( @generic_impl [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $inner_type : ty, $ffi_name: ty, $ffi_class_name: ty, @type_ $get_type_expr: expr) => {
689
+ ( @generic_impl [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $impl_type : ty , $parent_type : ty, $ffi_name: ty, $ffi_class_name: ty, @type_ $get_type_expr: expr) => {
687
690
$( #[ $attr] ) *
688
691
#[ repr( transparent) ]
689
692
$visibility struct $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? {
690
- inner: $crate:: object:: TypedObjectRef <$inner_type >,
693
+ inner: $crate:: object:: TypedObjectRef <$impl_type , $parent_type >,
691
694
phantom: std:: marker:: PhantomData <( $( $( $generic) ,+) ?) >,
692
695
}
693
696
@@ -1182,27 +1185,27 @@ macro_rules! glib_object_wrapper {
1182
1185
1183
1186
// This case is only for glib::Object itself below. All other cases have glib::Object in its
1184
1187
// parent class list
1185
- ( @object [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $inner_type : ty, $ffi_name: ty, @ffi_class $ffi_class_name: ty, @type_ $get_type_expr: expr) => {
1188
+ ( @object [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $impl_type : ty , $parent_type : ty, $ffi_name: ty, @ffi_class $ffi_class_name: ty, @type_ $get_type_expr: expr) => {
1186
1189
$crate:: glib_object_wrapper!(
1187
- @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $inner_type , $ffi_name, $ffi_class_name,
1190
+ @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $impl_type , $parent_type , $ffi_name, $ffi_class_name,
1188
1191
@type_ $get_type_expr) ;
1189
1192
1190
1193
#[ doc( hidden) ]
1191
1194
unsafe impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: object:: IsClass for $name $( <$( $generic) ,+>) ? { }
1192
1195
} ;
1193
1196
1194
- ( @object [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $inner_type : ty, $ffi_name: ty,
1197
+ ( @object [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $impl_type : ty , $parent_type : ty, $ffi_name: ty,
1195
1198
@type_ $get_type_expr: expr, @extends [ $( $extends: tt) * ] , @implements [ $( $implements: tt) * ] ) => {
1196
1199
$crate:: glib_object_wrapper!(
1197
- @object [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $inner_type , $ffi_name, @ffi_class std:: os:: raw:: c_void,
1200
+ @object [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $impl_type , $parent_type , $ffi_name, @ffi_class std:: os:: raw:: c_void,
1198
1201
@type_ $get_type_expr, @extends [ $( $extends) * ] , @implements [ $( $implements) * ]
1199
1202
) ;
1200
1203
} ;
1201
1204
1202
- ( @object [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $inner_type : ty, $ffi_name: ty, @ffi_class $ffi_class_name: ty,
1205
+ ( @object [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $impl_type : ty , $parent_type : ty, $ffi_name: ty, @ffi_class $ffi_class_name: ty,
1203
1206
@type_ $get_type_expr: expr, @extends [ $( $extends: tt) * ] , @implements [ $( $implements: tt) * ] ) => {
1204
1207
$crate:: glib_object_wrapper!(
1205
- @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $inner_type , $ffi_name, $ffi_class_name,
1208
+ @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $impl_type , $parent_type , $ffi_name, $ffi_class_name,
1206
1209
@type_ $get_type_expr
1207
1210
) ;
1208
1211
@@ -1224,11 +1227,29 @@ macro_rules! glib_object_wrapper {
1224
1227
unsafe impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: object:: IsClass for $name $( <$( $generic) ,+>) ? { }
1225
1228
} ;
1226
1229
1230
+ // FIXME: Workaround for `glib::Object` not being `Send+Sync` but subclasses of it being both
1231
+ // if the impl struct is.
1232
+ ( @object_subclass [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $subclass: ty,
1233
+ @extends [ ] , @implements [ $( $implements: tt) * ] ) => {
1234
+ $crate:: glib_object_wrapper!(
1235
+ @object [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?,
1236
+ $subclass, ( ) ,
1237
+ <$subclass as $crate:: subclass:: types:: ObjectSubclass >:: Instance ,
1238
+ @ffi_class <$subclass as $crate:: subclass:: types:: ObjectSubclass >:: Class ,
1239
+ @type_ $crate:: translate:: IntoGlib :: into_glib( <$subclass as $crate:: subclass:: types:: ObjectSubclassType >:: type_( ) ) ,
1240
+ @extends [ ] , @implements [ $( $implements) * ]
1241
+ ) ;
1242
+
1243
+ unsafe impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: object:: ObjectSubclassIs for $name $( <$( $generic) ,+>) ? {
1244
+ type Subclass = $subclass;
1245
+ }
1246
+ } ;
1247
+
1227
1248
( @object_subclass [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $subclass: ty,
1228
- @extends [ $( $extends: tt) * ] , @implements [ $( $implements: tt) * ] ) => {
1249
+ @extends [ $( $extends: tt) + ] , @implements [ $( $implements: tt) * ] ) => {
1229
1250
$crate:: glib_object_wrapper!(
1230
1251
@object [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?,
1231
- $subclass,
1252
+ $subclass, <$subclass as $crate :: subclass :: types :: ObjectSubclass > :: ParentType ,
1232
1253
<$subclass as $crate:: subclass:: types:: ObjectSubclass >:: Instance ,
1233
1254
@ffi_class <$subclass as $crate:: subclass:: types:: ObjectSubclass >:: Class ,
1234
1255
@type_ $crate:: translate:: IntoGlib :: into_glib( <$subclass as $crate:: subclass:: types:: ObjectSubclassType >:: type_( ) ) ,
@@ -1240,18 +1261,18 @@ macro_rules! glib_object_wrapper {
1240
1261
}
1241
1262
} ;
1242
1263
1243
- ( @interface [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $inner_type : ty, $ffi_name: ty,
1264
+ ( @interface [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $impl_type : ty, $ffi_name: ty,
1244
1265
@type_ $get_type_expr: expr, @requires [ $( $requires: tt) * ] ) => {
1245
1266
$crate:: glib_object_wrapper!(
1246
- @interface [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $inner_type , $ffi_name, @ffi_class std:: os:: raw:: c_void,
1267
+ @interface [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $impl_type , $ffi_name, @ffi_class std:: os:: raw:: c_void,
1247
1268
@type_ $get_type_expr, @requires [ $( $requires) * ]
1248
1269
) ;
1249
1270
} ;
1250
1271
1251
- ( @interface [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $inner_type : ty, $ffi_name: ty, @ffi_class $ffi_class_name: ty,
1272
+ ( @interface [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $impl_type : ty, $ffi_name: ty, @ffi_class $ffi_class_name: ty,
1252
1273
@type_ $get_type_expr: expr, @requires [ $( $requires: tt) * ] ) => {
1253
1274
$crate:: glib_object_wrapper!(
1254
- @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $inner_type , $ffi_name, $ffi_class_name,
1275
+ @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $impl_type , ( ) , $ffi_name, $ffi_class_name,
1255
1276
@type_ $get_type_expr
1256
1277
) ;
1257
1278
$crate:: glib_object_wrapper!( @munch_impls $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $( $requires) * ) ;
@@ -1273,7 +1294,7 @@ macro_rules! glib_object_wrapper {
1273
1294
1274
1295
glib_object_wrapper ! ( @object
1275
1296
[ doc = "The base class in the object hierarchy." ]
1276
- pub Object , * mut std:: os:: raw:: c_void, GObject , @ffi_class GObjectClass , @type_ gobject_ffi:: g_object_get_type( )
1297
+ pub Object , * mut std:: os:: raw:: c_void, ( ) , GObject , @ffi_class GObjectClass , @type_ gobject_ffi:: g_object_get_type( )
1277
1298
) ;
1278
1299
pub type ObjectClass = Class < Object > ;
1279
1300
0 commit comments