1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
/*! Objective-C Runtime bindings and wrapper for Rust. # Messaging objects Objective-C objects can be messaged using the [`msg_send!`](macro.msg_send!.html) macro: ``` # #[macro_use] extern crate objc; # use objc::runtime::{BOOL, Class, Object}; # fn main() { # unsafe { let cls = Class::get("NSObject").unwrap(); 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]; # } # } ``` # Declaring classes Objective-C classes can even be declared from Rust using the functionality of the [`declare`](declare/index.html) 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. */ #![crate_name = "objc"] #![crate_type = "lib"] #![warn(missing_docs)] extern crate libc; extern crate malloc_buf; #[cfg(feature = "exception")] extern crate objc_exception; pub use encode::{Encode, Encoding}; pub use message::{Message, MessageArguments}; #[macro_use] mod macros; pub mod runtime; pub mod declare; mod encode; #[cfg(feature = "exception")] mod exception; #[cfg(any(test, feature = "exception"))] mod id; mod message; #[cfg(test)] mod test_utils;