File tree 6 files changed +54
-1
lines changed 6 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,14 @@ unsafe impl<'a> ClassType for MyObject<'a> {
117
117
118
118
Class :: get ( "MyObject" ) . unwrap ( )
119
119
}
120
+
121
+ fn as_super ( & self ) -> & Self :: Super {
122
+ & self . superclass
123
+ }
124
+
125
+ fn as_super_mut ( & mut self ) -> & mut Self :: Super {
126
+ & mut self . superclass
127
+ }
120
128
}
121
129
122
130
fn main ( ) {
Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ use crate::Message;
17
17
/// # Safety
18
18
///
19
19
/// The class returned by [`Self::class`] must be a subclass of the class that
20
- /// [`Self::Super`] represents.
20
+ /// [`Self::Super`] represents, and `as_super`/`as_super_mut` must be
21
+ /// implemented correctly.
21
22
///
22
23
/// In pseudocode:
23
24
/// ```ignore
@@ -78,4 +79,12 @@ pub unsafe trait ClassType: Message {
78
79
/// class, e.g. if the program is not properly linked to the framework
79
80
/// that defines the class.
80
81
fn class ( ) -> & ' static Class ;
82
+
83
+ /// Get an immutable reference to the superclass.
84
+ // Note: It'd be safe to provide a default impl using transmute here if
85
+ // we wanted to!
86
+ fn as_super ( & self ) -> & Self :: Super ;
87
+
88
+ /// Get a mutable reference to the superclass.
89
+ fn as_super_mut ( & mut self ) -> & mut Self :: Super ;
81
90
}
Original file line number Diff line number Diff line change @@ -22,6 +22,14 @@ unsafe impl ClassType for NSObject {
22
22
fn class ( ) -> & ' static Class {
23
23
class ! ( NSObject )
24
24
}
25
+
26
+ fn as_super ( & self ) -> & Self :: Super {
27
+ & self . __inner
28
+ }
29
+
30
+ fn as_super_mut ( & mut self ) -> & mut Self :: Super {
31
+ & mut self . __inner
32
+ }
25
33
}
26
34
27
35
extern_methods ! (
Original file line number Diff line number Diff line change @@ -454,6 +454,16 @@ macro_rules! declare_class {
454
454
// We just registered the class, so it should be available
455
455
$crate:: runtime:: Class :: get( stringify!( $name) ) . unwrap( )
456
456
}
457
+
458
+ #[ inline]
459
+ fn as_super( & self ) -> & Self :: Super {
460
+ & self . __inner
461
+ }
462
+
463
+ #[ inline]
464
+ fn as_super_mut( & mut self ) -> & mut Self :: Super {
465
+ & mut self . __inner
466
+ }
457
467
}
458
468
459
469
// Methods
Original file line number Diff line number Diff line change @@ -259,6 +259,16 @@ macro_rules! __inner_extern_class {
259
259
fn class( ) -> & ' static $crate:: runtime:: Class {
260
260
$crate:: class!( $name)
261
261
}
262
+
263
+ #[ inline]
264
+ fn as_super( & self ) -> & Self :: Super {
265
+ & self . __inner
266
+ }
267
+
268
+ #[ inline]
269
+ fn as_super_mut( & mut self ) -> & mut Self :: Super {
270
+ & mut self . __inner
271
+ }
262
272
}
263
273
} ;
264
274
(
Original file line number Diff line number Diff line change @@ -26,6 +26,14 @@ unsafe impl ClassType for MyTestObject {
26
26
fn class ( ) -> & ' static Class {
27
27
class ! ( MyTestObject )
28
28
}
29
+
30
+ fn as_super ( & self ) -> & Self :: Super {
31
+ & self . inner
32
+ }
33
+
34
+ fn as_super_mut ( & mut self ) -> & mut Self :: Super {
35
+ & mut self . inner
36
+ }
29
37
}
30
38
31
39
impl MyTestObject {
You can’t perform that action at this time.
0 commit comments