Debian Codegraph @

third_party/rust/objc/src/lib.rs

raw
1 /*!
2 Objective-C Runtime bindings and wrapper for Rust.
3
4 # Messaging objects
5
6 Objective-C objects can be messaged using the [`msg_send!`](macro.msg_send!.html) macro:
7
8 ``` no_run
9 # #[macro_use] extern crate objc;
10 # use objc::runtime::{BOOL, Class, Object};
11 # fn main() {
12 # unsafe {
13 let cls = class!(NSObject);
14 let obj: *mut Object = msg_send![cls, new];
15 let hash: usize = msg_send![obj, hash];
16 let is_kind: BOOL = msg_send![obj, isKindOfClass:cls];
17 // Even void methods must have their return type annotated
18 let _: () = msg_send![obj, release];
19 # }
20 # }
21 ```
22
23 # Reference counting
24
25 Utilities for reference counting Objective-C objects are provided in the
26 [`rc`](rc/index.html) module.
27
28 # Declaring classes
29
30 Objective-C classes can even be declared from Rust using the functionality of
31 the [`declare`](declare/index.html) module.
32
33 # Exceptions
34
35 By default, if the `msg_send!` macro causes an exception to be thrown, this
36 will unwind into Rust resulting in unsafe, undefined behavior.
37 However, this crate has an `"exception"` feature which, when enabled, wraps
38 each `msg_send!` in a `@try`/`@catch` and panics if an exception is caught,
39 preventing Objective-C from unwinding into Rust.
40
41 # Message type verification
42
43 The Objective-C runtime includes encodings for each method that describe the
44 argument and return types. This crate can take advantage of these encodings to
45 verify that the types used in Rust match the types encoded for the method.
46
47 To use this functionality, enable the `"verify_message"` feature.
48 With this feature enabled, type checking is performed for every message send,
49 which also requires that all arguments and return values for all messages
50 implement `Encode`.
51
52 If this requirement is burdensome or you'd rather
53 just verify specific messages, you can call the
54 [`Message::verify_message`](trait.Message.html#method.verify_message) method
55 for specific selectors.
56
57 # Support for other Operating Systems
58
59 The bindings can be used on Linux or *BSD utilizing the
60 [GNUstep Objective-C runtime](https://www.github.com/gnustep/libobjc2).
61 */
62
63 #![crate_name = "objc"]
64 #![crate_type = "lib"]
65
66 #![warn(missing_docs)]
67
68 extern crate malloc_buf;
69 #[cfg(feature = "exception")]
70 extern crate objc_exception;
71
72 pub use encode::{Encode, EncodeArguments, Encoding};
73 pub use message::{Message, MessageArguments, MessageError};
74
75 pub use message::send_message as __send_message;
76 pub use message::send_super_message as __send_super_message;
77
78 #[macro_use]
79 mod macros;
80
81 pub mod runtime;
82 pub mod declare;
83 pub mod rc;
84 mod encode;
85 #[cfg(feature = "exception")]
86 mod exception;
87 mod message;
88
89 #[cfg(test)]
90 mod test_utils;