Skip to content

Commit e29349f

Browse files
committed
Better document MessageArguments::invoke and add Encode bound on return
1 parent a94fd59 commit e29349f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

objc2/src/message/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,19 @@ pub trait MessageArguments: EncodeArguments {
286286
/// This method is the primitive used when sending messages and should not
287287
/// be called directly; instead, use the `msg_send!` macro or, in cases
288288
/// with a dynamic selector, the [`MessageReceiver::send_message`] method.
289-
unsafe fn invoke<R>(imp: Imp, obj: *mut Object, sel: Sel, args: Self) -> R;
289+
unsafe fn invoke<R: Encode>(imp: Imp, obj: *mut Object, sel: Sel, args: Self) -> R;
290290
}
291291

292292
macro_rules! message_args_impl {
293293
($($a:ident : $t:ident),*) => (
294294
impl<$($t: Encode),*> MessageArguments for ($($t,)*) {
295-
unsafe fn invoke<R>(imp: Imp, obj: *mut Object, sel: Sel, ($($a,)*): Self) -> R {
296-
let imp: unsafe extern fn(*mut Object, Sel $(, $t)*) -> R =
297-
mem::transmute(imp);
295+
#[inline]
296+
unsafe fn invoke<R: Encode>(imp: Imp, obj: *mut Object, sel: Sel, ($($a,)*): Self) -> R {
297+
// The imp must be cast to the appropriate function pointer
298+
// type before being called; the msgSend functions are not
299+
// parametric, but instead "trampolines" to the actual
300+
// method implementations.
301+
let imp: unsafe extern "C" fn(*mut Object, Sel $(, $t)*) -> R = mem::transmute(imp);
298302
imp(obj, sel $(, $a)*)
299303
}
300304
}

0 commit comments

Comments
 (0)