|
| 1 | +use core::mem::ManuallyDrop; |
| 2 | + |
1 | 3 | use crate::rc::{Id, Ownership};
|
2 | 4 | use crate::runtime::{Class, Sel};
|
3 | 5 | use crate::{Message, MessageArguments, MessageError, MessageReceiver};
|
@@ -84,6 +86,27 @@ impl<X: Into<Option<Id<T, O>>>, T: ?Sized + Message, O: Ownership> MsgSendId<X,
|
84 | 86 | }
|
85 | 87 | }
|
86 | 88 |
|
| 89 | +// Super: `init`. Takes a non-null object and returns a non-initialized object |
| 90 | +// |
| 91 | +// Should theoretically make it easy to use in declared `init` methods, once |
| 92 | +// they've received an ergonomics overhaul |
| 93 | +impl<T: ?Sized + Message, O: Ownership> MsgSendSuperId<Id<T, O>, Id<T, O>> |
| 94 | + for Assert<false, false, true, false> |
| 95 | +{ |
| 96 | + #[inline(always)] |
| 97 | + unsafe fn send_super_message_id<A: MessageArguments>( |
| 98 | + obj: Id<T, O>, |
| 99 | + superclass: &Class, |
| 100 | + sel: Sel, |
| 101 | + args: A, |
| 102 | + ) -> Result<Option<Id<T, O>>, MessageError> { |
| 103 | + let ptr = Id::consume_as_ptr(ManuallyDrop::new(obj)); |
| 104 | + unsafe { |
| 105 | + MessageReceiver::send_super_message(ptr, superclass, sel, args).map(|r| Id::new(r)) |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | + |
87 | 110 | // `copy` and `mutableCopy`
|
88 | 111 | impl<T: MessageReceiver, U: ?Sized + Message, O: Ownership> MsgSendId<T, Id<U, O>>
|
89 | 112 | for Assert<false, false, false, true>
|
@@ -242,7 +265,11 @@ mod tests {
|
242 | 265 | // superclass, just to verify that the macro works.
|
243 | 266 | // TODO: Better solution!
|
244 | 267 | let cls = class!(NSObject);
|
245 |
| - let obj: Id<Object, Owned> = unsafe { msg_send_id![cls, new].unwrap() }; |
| 268 | + |
| 269 | + let obj = unsafe { msg_send_id![cls, alloc] }; |
| 270 | + |
| 271 | + let obj = obj.unwrap(); // Required on super |
| 272 | + let obj: Id<Object, Owned> = unsafe { msg_send_id![super(obj, cls), init].unwrap() }; |
246 | 273 |
|
247 | 274 | let _desc: Option<Id<Object, Shared>> =
|
248 | 275 | unsafe { msg_send_id![super(&obj, cls), description] };
|
|
0 commit comments