pub unsafe trait MessageReceiver: Sealed + Sized {
    unsafe fn send_message<A, R>(
        self,
        sel: Sel,
        args: A
    ) -> Result<R, MessageError>
    where
        A: MessageArguments,
        R: Encode
, { ... } unsafe fn send_super_message<A, R>(
        self,
        superclass: &Class,
        sel: Sel,
        args: A
    ) -> Result<R, MessageError>
    where
        A: MessageArguments,
        R: Encode
, { ... } fn verify_message<A, R>(self, sel: Sel) -> Result<(), MessageError>
    where
        A: EncodeArguments,
        R: Encode
, { ... } }
Expand description

Types that can directly be used as the receiver of Objective-C messages.

Examples include objects, classes, and blocks.

This is a sealed trait (for now) that is automatically implemented for pointers to types implementing Message, so that code can be generic over the message receiver.

This is mostly an implementation detail; you’ll want to implement Message for your type instead.

Safety

This is a sealed trait, and should not need to be implemented. Open an issue if you know a use-case where this restrition should be lifted!

Provided Methods

Sends a message to self with the given selector and arguments.

The correct version of objc_msgSend will be chosen based on the return type. For more information, see the section on “Sending Messages” in Apple’s documentation.

If the selector is known at compile-time, it is recommended to use the msg_send! macro rather than this method.

Safety

This shares the same safety requirements as msg_send!.

The added invariant is that the selector must take the same number of arguments as is given.

Sends a message to self’s superclass with the given selector and arguments.

The correct version of objc_msgSend_super will be chosen based on the return type. For more information, see the section on “Sending Messages” in Apple’s documentation.

If the selector is known at compile-time, it is recommended to use the msg_send!(super) macro rather than this method.

Safety

This shares the same safety requirements as msg_send!(super(...), ...).

The added invariant is that the selector must take the same number of arguments as is given.

Verify that the argument and return types match the encoding of the method for the given selector.

This will look up the encoding of the method for the given selector, sel, and return a MessageError if any encodings differ for the arguments A and return type R.

Example
let obj: &Object;
let sel = sel!(isKindOfClass:);
// Verify isKindOfClass: takes one Class and returns a BOOL
let result = obj.verify_message::<(&Class,), Bool>(sel);
assert!(result.is_ok());

Implementations on Foreign Types

Implementors