@@ -597,15 +597,97 @@ impl FromGlibPtrArrayContainerAsVec<*mut GObject, *const *mut GObject> for Objec
597
597
}
598
598
}
599
599
600
+ #[ repr( transparent) ]
601
+ pub struct TypedObjectRef < T > {
602
+ inner : ObjectRef ,
603
+ phantom : PhantomData < T > ,
604
+ }
605
+
606
+ impl < T > TypedObjectRef < T > {
607
+ pub unsafe fn new ( obj : ObjectRef ) -> Self {
608
+ Self {
609
+ inner : obj,
610
+ phantom : PhantomData ,
611
+ }
612
+ }
613
+
614
+ pub fn into_inner ( self ) -> ObjectRef {
615
+ self . inner
616
+ }
617
+ }
618
+
619
+ impl < T > Clone for TypedObjectRef < T > {
620
+ fn clone ( & self ) -> Self {
621
+ Self {
622
+ inner : self . inner . clone ( ) ,
623
+ phantom : PhantomData ,
624
+ }
625
+ }
626
+ }
627
+
628
+ impl < T > ops:: Deref for TypedObjectRef < T > {
629
+ type Target = ObjectRef ;
630
+
631
+ fn deref ( & self ) -> & Self :: Target {
632
+ & self . inner
633
+ }
634
+ }
635
+
636
+ impl < T > fmt:: Debug for TypedObjectRef < T > {
637
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
638
+ let type_ = unsafe {
639
+ let klass = ( * self . inner . inner . as_ptr ( ) ) . g_type_instance . g_class as * const ObjectClass ;
640
+ ( * klass) . type_ ( )
641
+ } ;
642
+
643
+ f. debug_struct ( "TypedObjectRef" )
644
+ . field ( "inner" , & self . inner . inner )
645
+ . field ( "type" , & type_)
646
+ . finish ( )
647
+ }
648
+ }
649
+
650
+ impl < T > PartialOrd for TypedObjectRef < T > {
651
+ fn partial_cmp ( & self , other : & Self ) -> Option < cmp:: Ordering > {
652
+ self . inner . partial_cmp ( & other. inner )
653
+ }
654
+ }
655
+
656
+ impl < T > Ord for TypedObjectRef < T > {
657
+ fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
658
+ self . inner . cmp ( & other. inner )
659
+ }
660
+ }
661
+
662
+ impl < T > PartialEq for TypedObjectRef < T > {
663
+ fn eq ( & self , other : & Self ) -> bool {
664
+ self . inner == other. inner
665
+ }
666
+ }
667
+
668
+ impl < T > Eq for TypedObjectRef < T > { }
669
+
670
+ impl < T > hash:: Hash for TypedObjectRef < T > {
671
+ fn hash < H > ( & self , state : & mut H )
672
+ where
673
+ H : hash:: Hasher ,
674
+ {
675
+ self . inner . hash ( state)
676
+ }
677
+ }
678
+
679
+ unsafe impl < T : Send + Sync > Send for TypedObjectRef < T > { }
680
+ unsafe impl < T : Send + Sync > Sync for TypedObjectRef < T > { }
681
+
600
682
// rustdoc-stripper-ignore-next
601
683
/// ObjectType implementations for Object types. See `wrapper!`.
602
684
#[ macro_export]
603
685
macro_rules! glib_object_wrapper {
604
- ( @generic_impl [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $ffi_name: ty, $ffi_class_name: ty, @type_ $get_type_expr: expr) => {
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) => {
605
687
$( #[ $attr] ) *
606
688
#[ repr( transparent) ]
607
689
$visibility struct $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? {
608
- inner: $crate:: object:: ObjectRef ,
690
+ inner: $crate:: object:: TypedObjectRef <$inner_type> ,
609
691
phantom: std:: marker:: PhantomData <( $( $( $generic) ,+) ?) >,
610
692
}
611
693
@@ -639,7 +721,7 @@ macro_rules! glib_object_wrapper {
639
721
impl <OT : $crate:: object:: ObjectType $( , $( $generic $( : $bound $( + $bound2) * ) ?) ,+) ?> std:: cmp:: PartialEq <OT > for $name $( <$( $generic) ,+>) ? {
640
722
#[ inline]
641
723
fn eq( & self , other: & OT ) -> bool {
642
- std:: cmp:: PartialEq :: eq( & self . inner, $crate:: object:: ObjectType :: as_object_ref( other) )
724
+ std:: cmp:: PartialEq :: eq( & * self . inner, $crate:: object:: ObjectType :: as_object_ref( other) )
643
725
}
644
726
}
645
727
@@ -648,14 +730,14 @@ macro_rules! glib_object_wrapper {
648
730
impl <OT : $crate:: object:: ObjectType $( , $( $generic $( : $bound $( + $bound2) * ) ?) ,+) ?> std:: cmp:: PartialOrd <OT > for $name $( <$( $generic) ,+>) ? {
649
731
#[ inline]
650
732
fn partial_cmp( & self , other: & OT ) -> Option <std:: cmp:: Ordering > {
651
- std:: cmp:: PartialOrd :: partial_cmp( & self . inner, $crate:: object:: ObjectType :: as_object_ref( other) )
733
+ std:: cmp:: PartialOrd :: partial_cmp( & * self . inner, $crate:: object:: ObjectType :: as_object_ref( other) )
652
734
}
653
735
}
654
736
655
737
impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? std:: cmp:: Ord for $name $( <$( $generic) ,+>) ? {
656
738
#[ inline]
657
739
fn cmp( & self , other: & Self ) -> std:: cmp:: Ordering {
658
- std:: cmp:: Ord :: cmp( & self . inner, $crate:: object:: ObjectType :: as_object_ref( other) )
740
+ std:: cmp:: Ord :: cmp( & * self . inner, $crate:: object:: ObjectType :: as_object_ref( other) )
659
741
}
660
742
}
661
743
@@ -668,15 +750,15 @@ macro_rules! glib_object_wrapper {
668
750
#[ doc( hidden) ]
669
751
impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? From <$name $( <$( $generic) ,+>) ?> for $crate:: object:: ObjectRef {
670
752
fn from( s: $name $( <$( $generic) ,+>) ?) -> $crate:: object:: ObjectRef {
671
- s. inner
753
+ s. inner. into_inner ( )
672
754
}
673
755
}
674
756
675
757
#[ doc( hidden) ]
676
758
impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: translate:: UnsafeFrom <$crate:: object:: ObjectRef > for $name $( <$( $generic) ,+>) ? {
677
759
unsafe fn unsafe_from( t: $crate:: object:: ObjectRef ) -> Self {
678
760
$name {
679
- inner: t ,
761
+ inner: $crate :: object :: TypedObjectRef :: new ( t ) ,
680
762
phantom: std:: marker:: PhantomData ,
681
763
}
682
764
}
@@ -697,7 +779,7 @@ macro_rules! glib_object_wrapper {
697
779
}
698
780
699
781
fn as_ptr( & self ) -> * mut Self :: GlibType {
700
- $crate:: translate:: ToGlibPtr :: to_glib_none( & self . inner) . 0 as * mut _
782
+ $crate:: translate:: ToGlibPtr :: to_glib_none( & * self . inner) . 0 as * mut _
701
783
}
702
784
}
703
785
@@ -733,13 +815,13 @@ macro_rules! glib_object_wrapper {
733
815
734
816
#[ inline]
735
817
fn to_glib_none( & ' a self ) -> $crate:: translate:: Stash <' a, * const $ffi_name, Self > {
736
- let stash = $crate:: translate:: ToGlibPtr :: to_glib_none( & self . inner) ;
818
+ let stash = $crate:: translate:: ToGlibPtr :: to_glib_none( & * self . inner) ;
737
819
$crate:: translate:: Stash ( stash. 0 as * const _, stash. 1 )
738
820
}
739
821
740
822
#[ inline]
741
823
fn to_glib_full( & self ) -> * const $ffi_name {
742
- $crate:: translate:: ToGlibPtr :: to_glib_full( & self . inner) as * const _
824
+ $crate:: translate:: ToGlibPtr :: to_glib_full( & * self . inner) as * const _
743
825
}
744
826
}
745
827
@@ -750,13 +832,13 @@ macro_rules! glib_object_wrapper {
750
832
751
833
#[ inline]
752
834
fn to_glib_none( & ' a self ) -> $crate:: translate:: Stash <' a, * mut $ffi_name, Self > {
753
- let stash = $crate:: translate:: ToGlibPtr :: to_glib_none( & self . inner) ;
835
+ let stash = $crate:: translate:: ToGlibPtr :: to_glib_none( & * self . inner) ;
754
836
$crate:: translate:: Stash ( stash. 0 as * mut _, stash. 1 )
755
837
}
756
838
757
839
#[ inline]
758
840
fn to_glib_full( & self ) -> * mut $ffi_name {
759
- $crate:: translate:: ToGlibPtr :: to_glib_full( & self . inner) as * mut _
841
+ $crate:: translate:: ToGlibPtr :: to_glib_full( & * self . inner) as * mut _
760
842
}
761
843
}
762
844
@@ -828,7 +910,7 @@ macro_rules! glib_object_wrapper {
828
910
unsafe fn from_glib_none( ptr: * mut $ffi_name) -> Self {
829
911
debug_assert!( $crate:: types:: instance_of:: <Self >( ptr as * const _) ) ;
830
912
$name {
831
- inner: $crate:: translate:: from_glib_none( ptr as * mut _) ,
913
+ inner: $crate:: object :: TypedObjectRef :: new ( $crate :: translate:: from_glib_none( ptr as * mut _) ) ,
832
914
phantom: std:: marker:: PhantomData ,
833
915
}
834
916
}
@@ -841,7 +923,7 @@ macro_rules! glib_object_wrapper {
841
923
unsafe fn from_glib_none( ptr: * const $ffi_name) -> Self {
842
924
debug_assert!( $crate:: types:: instance_of:: <Self >( ptr as * const _) ) ;
843
925
$name {
844
- inner: $crate:: translate:: from_glib_none( ptr as * mut _) ,
926
+ inner: $crate:: object :: TypedObjectRef :: new ( $crate :: translate:: from_glib_none( ptr as * mut _) ) ,
845
927
phantom: std:: marker:: PhantomData ,
846
928
}
847
929
}
@@ -854,7 +936,7 @@ macro_rules! glib_object_wrapper {
854
936
unsafe fn from_glib_full( ptr: * mut $ffi_name) -> Self {
855
937
debug_assert!( $crate:: types:: instance_of:: <Self >( ptr as * const _) ) ;
856
938
$name {
857
- inner: $crate:: translate:: from_glib_full( ptr as * mut _) ,
939
+ inner: $crate:: object :: TypedObjectRef :: new ( $crate :: translate:: from_glib_full( ptr as * mut _) ) ,
858
940
phantom: std:: marker:: PhantomData ,
859
941
}
860
942
}
@@ -868,7 +950,7 @@ macro_rules! glib_object_wrapper {
868
950
debug_assert!( $crate:: types:: instance_of:: <Self >( ptr as * const _) ) ;
869
951
$crate:: translate:: Borrowed :: new(
870
952
$name {
871
- inner: $crate:: translate:: from_glib_borrow:: <_, $crate:: object:: ObjectRef >( ptr as * mut _) . into_inner( ) ,
953
+ inner: $crate:: object :: TypedObjectRef :: new ( $crate :: translate:: from_glib_borrow:: <_, $crate:: object:: ObjectRef >( ptr as * mut _) . into_inner( ) ) ,
872
954
phantom: std:: marker:: PhantomData ,
873
955
}
874
956
)
@@ -1100,27 +1182,27 @@ macro_rules! glib_object_wrapper {
1100
1182
1101
1183
// This case is only for glib::Object itself below. All other cases have glib::Object in its
1102
1184
// parent class list
1103
- ( @object [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $ffi_name: ty, @ffi_class $ffi_class_name: ty, @type_ $get_type_expr: expr) => {
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) => {
1104
1186
$crate:: glib_object_wrapper!(
1105
- @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $ffi_name, $ffi_class_name,
1187
+ @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $inner_type , $ ffi_name, $ffi_class_name,
1106
1188
@type_ $get_type_expr) ;
1107
1189
1108
1190
#[ doc( hidden) ]
1109
1191
unsafe impl $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ? $crate:: object:: IsClass for $name $( <$( $generic) ,+>) ? { }
1110
1192
} ;
1111
1193
1112
- ( @object [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $ffi_name: ty,
1194
+ ( @object [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $inner_type : ty , $ ffi_name: ty,
1113
1195
@type_ $get_type_expr: expr, @extends [ $( $extends: tt) * ] , @implements [ $( $implements: tt) * ] ) => {
1114
1196
$crate:: glib_object_wrapper!(
1115
- @object [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $ffi_name, @ffi_class std:: os:: raw:: c_void,
1197
+ @object [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $inner_type , $ ffi_name, @ffi_class std:: os:: raw:: c_void,
1116
1198
@type_ $get_type_expr, @extends [ $( $extends) * ] , @implements [ $( $implements) * ]
1117
1199
) ;
1118
1200
} ;
1119
1201
1120
- ( @object [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $ffi_name: ty, @ffi_class $ffi_class_name: ty,
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,
1121
1203
@type_ $get_type_expr: expr, @extends [ $( $extends: tt) * ] , @implements [ $( $implements: tt) * ] ) => {
1122
1204
$crate:: glib_object_wrapper!(
1123
- @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $ffi_name, $ffi_class_name,
1205
+ @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $inner_type , $ ffi_name, $ffi_class_name,
1124
1206
@type_ $get_type_expr
1125
1207
) ;
1126
1208
@@ -1146,6 +1228,7 @@ macro_rules! glib_object_wrapper {
1146
1228
@extends [ $( $extends: tt) * ] , @implements [ $( $implements: tt) * ] ) => {
1147
1229
$crate:: glib_object_wrapper!(
1148
1230
@object [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?,
1231
+ $subclass,
1149
1232
<$subclass as $crate:: subclass:: types:: ObjectSubclass >:: Instance ,
1150
1233
@ffi_class <$subclass as $crate:: subclass:: types:: ObjectSubclass >:: Class ,
1151
1234
@type_ $crate:: translate:: IntoGlib :: into_glib( <$subclass as $crate:: subclass:: types:: ObjectSubclassType >:: type_( ) ) ,
@@ -1157,18 +1240,18 @@ macro_rules! glib_object_wrapper {
1157
1240
}
1158
1241
} ;
1159
1242
1160
- ( @interface [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $ffi_name: ty,
1243
+ ( @interface [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $inner_type : ty , $ ffi_name: ty,
1161
1244
@type_ $get_type_expr: expr, @requires [ $( $requires: tt) * ] ) => {
1162
1245
$crate:: glib_object_wrapper!(
1163
- @interface [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $ffi_name, @ffi_class std:: os:: raw:: c_void,
1246
+ @interface [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $inner_type , $ ffi_name, @ffi_class std:: os:: raw:: c_void,
1164
1247
@type_ $get_type_expr, @requires [ $( $requires) * ]
1165
1248
) ;
1166
1249
} ;
1167
1250
1168
- ( @interface [ $( $attr: meta) * ] $visibility: vis $name: ident $( <$( $generic: ident $( : $bound: tt $( + $bound2: tt) * ) ?) ,+>) ?, $ffi_name: ty, @ffi_class $ffi_class_name: ty,
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,
1169
1252
@type_ $get_type_expr: expr, @requires [ $( $requires: tt) * ] ) => {
1170
1253
$crate:: glib_object_wrapper!(
1171
- @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $ffi_name, $ffi_class_name,
1254
+ @generic_impl [ $( $attr) * ] $visibility $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $inner_type , $ ffi_name, $ffi_class_name,
1172
1255
@type_ $get_type_expr
1173
1256
) ;
1174
1257
$crate:: glib_object_wrapper!( @munch_impls $name $( <$( $generic $( : $bound $( + $bound2) * ) ?) ,+>) ?, $( $requires) * ) ;
@@ -1190,7 +1273,7 @@ macro_rules! glib_object_wrapper {
1190
1273
1191
1274
glib_object_wrapper ! ( @object
1192
1275
[ doc = "The base class in the object hierarchy." ]
1193
- pub Object , GObject , @ffi_class GObjectClass , @type_ gobject_ffi:: g_object_get_type( )
1276
+ pub Object , * mut std :: os :: raw :: c_void , GObject , @ffi_class GObjectClass , @type_ gobject_ffi:: g_object_get_type( )
1194
1277
) ;
1195
1278
pub type ObjectClass = Class < Object > ;
1196
1279
@@ -3720,11 +3803,11 @@ impl<'a> BindingBuilder<'a> {
3720
3803
3721
3804
unsafe {
3722
3805
let source = Object {
3723
- inner : self . source . clone ( ) ,
3806
+ inner : TypedObjectRef :: new ( self . source . clone ( ) ) ,
3724
3807
phantom : std:: marker:: PhantomData ,
3725
3808
} ;
3726
3809
let target = Object {
3727
- inner : self . target . clone ( ) ,
3810
+ inner : TypedObjectRef :: new ( self . target . clone ( ) ) ,
3728
3811
phantom : std:: marker:: PhantomData ,
3729
3812
} ;
3730
3813
0 commit comments