pub unsafe trait Message {
// Provided methods
unsafe fn send_message<A, R>(
&self,
sel: Sel,
args: A
) -> Result<R, MessageError>
where Self: Sized,
A: MessageArguments,
R: Any { ... }
fn verify_message<A, R>(&self, sel: Sel) -> Result<(), MessageError>
where Self: Sized,
A: EncodeArguments,
R: Encode { ... }
}
Expand description
Types that may be sent Objective-C messages. For example: objects, classes, and blocks.
Provided Methods§
sourceunsafe fn send_message<A, R>(
&self,
sel: Sel,
args: A
) -> Result<R, MessageError>where
Self: Sized,
A: MessageArguments,
R: Any,
unsafe fn send_message<A, R>( &self, sel: Sel, args: A ) -> Result<R, MessageError>where Self: Sized, A: MessageArguments, R: Any,
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 Apple’s documentation:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/index.html#//apple_ref/doc/uid/TP40001418-CH1g-88778
If the selector is known at compile-time, it is recommended to use the
msg_send!
macro rather than this method.
sourcefn verify_message<A, R>(&self, sel: Sel) -> Result<(), MessageError>where
Self: Sized,
A: EncodeArguments,
R: Encode,
fn verify_message<A, R>(&self, sel: Sel) -> Result<(), MessageError>where Self: Sized, A: EncodeArguments, R: Encode,
Verifies 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());