Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit 08731f2

Browse files
committed
glib: Implement AsRef/AsMut<T::GlibClassType> for Class<T>
This makes it easier/safer to implement `IsSubclassable`. This does not (yet) rewrite all the relevant code to use this method.
1 parent 3e29094 commit 08731f2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

glib/src/object.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,18 @@ impl<T: ObjectType> Class<T> {
25182518
unsafe impl<T: ObjectType> Send for Class<T> {}
25192519
unsafe impl<T: ObjectType> Sync for Class<T> {}
25202520

2521+
impl<T: ObjectType> AsRef<T::GlibClassType> for Class<T> {
2522+
fn as_ref(&self) -> &T::GlibClassType {
2523+
&self.0
2524+
}
2525+
}
2526+
2527+
impl<T: ObjectType> AsMut<T::GlibClassType> for Class<T> {
2528+
fn as_mut(&mut self) -> &mut T::GlibClassType {
2529+
&mut self.0
2530+
}
2531+
}
2532+
25212533
// This should require Self: IsA<Self::Super>, but that seems to cause a cycle error
25222534
pub unsafe trait ParentClassIs: ObjectType {
25232535
type Parent: ObjectType;

0 commit comments

Comments
 (0)