| __framework_prelude.rs |
Helper import prelude for framework crates. |
672 |
| __macro_helpers |
|
|
| downcast.rs |
|
1664 |
| encode.rs |
# Support for type-encodings.
The Objective-C runtime includes encodings for each method that describe
the argument and return types. This module contains traits for annotating
types that has an Objective-C type-encoding: Specifically [`Encode`] for
structs/numeric types and [`RefEncode`] for references.
Additionally, this exports the [`Encoding`] and [`EncodingBox`] types from
[`objc2-encode`][objc2_encode], see that crate for a few more details on
what Objective-C type-encodings are.
## Examples
Implementing [`Encode`] and [`RefEncode`] for a custom type:
```
use objc2::encode::{Encode, Encoding, RefEncode};
#[repr(C)]
struct MyStruct {
a: f32, // float
b: i16, // int16_t
}
unsafe impl Encode for MyStruct {
const ENCODING: Encoding = Encoding::Struct(
"MyStruct", // Must use the same name as defined in C header files
&[
f32::ENCODING, // Same as Encoding::Float
i16::ENCODING, // Same as Encoding::Short
],
);
}
// @encode(MyStruct) -> "{MyStruct=fs}"
assert!(MyStruct::ENCODING.equivalent_to_str("{MyStruct=fs}"));
unsafe impl RefEncode for MyStruct {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
// @encode(MyStruct*) -> "^{MyStruct=fs}"
assert!(MyStruct::ENCODING_REF.equivalent_to_str("^{MyStruct=fs}"));
```
Implementing [`Encode`] for a few core-graphics types.
Note that these are available in `objc2-foundation`, so the implementation
here is mostly for demonstration.
``` |
32751 |
| exception.rs |
# `@throw` and `@try/@catch` exceptions.
By default, if a message send (such as those generated with the
[`msg_send!`] and [`extern_methods!`] macros) causes an exception to be
thrown, `objc2` will simply let it unwind into Rust.
While not UB, it will likely end up aborting the process, since Rust
cannot catch foreign exceptions like Objective-C's. However, `objc2` has
the `"catch-all"` Cargo feature, which, when enabled, wraps each message
send in a `@catch` and instead panics if an exception is caught, which
might lead to slightly better error messages.
Most of the functionality in this module is only available when the
`"exception"` feature is enabled.
See the following links for more information:
- [Exception Programming Topics for Cocoa](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Exceptions/Exceptions.html)
- [The Objective-C Programming Language - Exception Handling](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocExceptionHandling.html)
- [Exception Handling in LLVM](https://llvm.org/docs/ExceptionHandling.html)
[`msg_send!`]: crate::msg_send |
15471 |
| ffi |
|
|
| lib.rs |
# Objective-C interface and runtime bindings
Quick links:
- [All Topics][crate::topics].
- [All examples].
- [About framework crates][crate::topics::about_generated].
- [List of framework crates][crate::topics::about_generated::list].
|
8309 |
| macros |
|
|
| main_thread_marker.rs |
This belongs in `std` IMO, but wasn't accepted there:
<https://github.com/rust-lang/rust/pull/136616> |
12265 |
| rc |
|
|
| runtime |
|
|
| test_utils.rs |
|
9211 |
| top_level_traits.rs |
|
20932 |
| topics |
|
|
| verify.rs |
|
12214 |