Crate objc2[−][src]
Expand description
Objective-C Runtime bindings and wrapper for Rust.
Messaging objects
Objective-C objects can be messaged using the msg_send!
macro:
let cls = class!(NSObject);
let obj: *mut Object = msg_send![cls, new];
let hash: usize = msg_send![obj, hash];
let is_kind: BOOL = msg_send![obj, isKindOfClass:cls];
// Even void methods must have their return type annotated
let _: () = msg_send![obj, release];
Reference counting
Utilities for reference counting Objective-C objects are provided in the
rc
module.
Declaring classes
Objective-C classes can even be declared from Rust using the functionality of
the declare
module.
Exceptions
By default, if the msg_send!
macro causes an exception to be thrown, this
will unwind into Rust resulting in unsafe, undefined behavior.
However, this crate has an "exception"
feature which, when enabled, wraps
each msg_send!
in a @try
/@catch
and panics if an exception is caught,
preventing Objective-C from unwinding into Rust.
Message type verification
The Objective-C runtime includes encodings for each method that describe the argument and return types. This crate can take advantage of these encodings to verify that the types used in Rust match the types encoded for the method.
To use this functionality, enable the "verify_message"
feature.
With this feature enabled, type checking is performed for every message send,
which also requires that all arguments and return values for all messages
implement Encode
.
If this requirement is burdensome or you’d rather
just verify specific messages, you can call the
Message::verify_message
method
for specific selectors.
Support for other Operating Systems
The bindings can be used on Linux or *BSD utilizing the GNUstep Objective-C runtime.
Modules
Functionality for declaring Objective-C classes.
Utilities for reference counting Objective-C objects.
A Rust interface for the functionality of the Objective-C runtime.
Macros
Sends a message to an object.
Registers a selector with the Objective-C runtime.
Structs
An error encountered while attempting to send a message.
Enums
An Objective-C type-encoding.
Traits
Types that have an Objective-C type-encoding.
Types that represent an ordered group of function arguments, where each argument has an Objective-C type-encoding.
This trait marks types that can be sent Objective-C messages.
Types that may be used as the arguments of an Objective-C message.
Types whoose references has an Objective-C type-encoding.