Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit ee61c14

Browse files
Merge pull request #426 from sdroege/deref-class-struct
Implement DerefMut for class structs too
2 parents 921dd31 + 5900cec commit ee61c14

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/object.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -679,10 +679,7 @@ macro_rules! glib_object_wrapper {
679679
#[doc(hidden)]
680680
impl AsRef<$super_name> for $name {
681681
fn as_ref(&self) -> &$super_name {
682-
debug_assert!($crate::object::ObjectExt::is::<$super_name>(self));
683-
unsafe {
684-
::std::mem::transmute(self)
685-
}
682+
$crate::object::Cast::upcast_ref(self)
686683
}
687684
}
688685
};
@@ -700,9 +697,13 @@ macro_rules! glib_object_wrapper {
700697
type Target = <$crate::object::Object as $crate::object::ObjectType>::RustClassType;
701698

702699
fn deref(&self) -> &Self::Target {
703-
unsafe {
704-
::std::mem::transmute(self)
705-
}
700+
$crate::object::IsClassFor::upcast_ref(self)
701+
}
702+
}
703+
704+
impl ::std::ops::DerefMut for $rust_class_name {
705+
fn deref_mut(&mut self) -> &mut Self::Target {
706+
$crate::object::IsClassFor::upcast_ref_mut(self)
706707
}
707708
}
708709
};
@@ -715,9 +716,13 @@ macro_rules! glib_object_wrapper {
715716
type Target = <$super_name as $crate::object::ObjectType>::RustClassType;
716717

717718
fn deref(&self) -> &Self::Target {
718-
unsafe {
719-
::std::mem::transmute(self)
720-
}
719+
$crate::object::IsClassFor::upcast_ref(self)
720+
}
721+
}
722+
723+
impl ::std::ops::DerefMut for $rust_class_name {
724+
fn deref_mut(&mut self) -> &mut Self::Target {
725+
$crate::object::IsClassFor::upcast_ref_mut(self)
721726
}
722727
}
723728
};
@@ -730,9 +735,13 @@ macro_rules! glib_object_wrapper {
730735
type Target = <$super_name as $crate::object::ObjectType>::RustClassType;
731736

732737
fn deref(&self) -> &Self::Target {
733-
unsafe {
734-
::std::mem::transmute(self)
735-
}
738+
$crate::object::IsClassFor::upcast_ref(self)
739+
}
740+
}
741+
742+
impl ::std::ops::DerefMut for $rust_class_name {
743+
fn deref_mut(&mut self) -> &mut Self::Target {
744+
$crate::object::IsClassFor::upcast_ref_mut(self)
736745
}
737746
}
738747

@@ -770,10 +779,7 @@ macro_rules! glib_object_wrapper {
770779
#[doc(hidden)]
771780
impl AsRef<$crate::object::Object> for $name {
772781
fn as_ref(&self) -> &$crate::object::Object {
773-
debug_assert!($crate::object::ObjectExt::is::<$crate::object::Object>(self));
774-
unsafe {
775-
::std::mem::transmute(self)
776-
}
782+
$crate::object::Cast::upcast_ref(self)
777783
}
778784
}
779785

@@ -789,10 +795,7 @@ macro_rules! glib_object_wrapper {
789795
#[doc(hidden)]
790796
impl AsRef<$crate::object::Object> for $name {
791797
fn as_ref(&self) -> &$crate::object::Object {
792-
debug_assert!($crate::object::ObjectExt::is::<$crate::object::Object>(self));
793-
unsafe {
794-
::std::mem::transmute(self)
795-
}
798+
$crate::object::Cast::upcast_ref(self)
796799
}
797800
}
798801

0 commit comments

Comments
 (0)