Skip to content

Commit d9cb5c2

Browse files
authored
Merge pull request #7 from madsmtm/no-uninhabited-enum
Use structs to represent objects instead of uninhabited enums
2 parents 44cca2b + cc1430a commit d9cb5c2

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

examples/foundation_custom_class.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ use objc::runtime::{Class, Object, Sel};
66
use objc::Message;
77
use objc_foundation::{INSObject, NSObject};
88

9-
pub enum MYObject {}
9+
/// In the future this should be an `extern type`, if that gets stabilized,
10+
/// see [RFC-1861](https://rust-lang.github.io/rfcs/1861-extern-types.html).
11+
#[repr(C)]
12+
pub struct MYObject {
13+
/// See the [Nomicon] for details on representing opaque structs.
14+
///
15+
/// [Nomicon]: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
16+
_priv: [u8; 0],
17+
}
1018

1119
impl MYObject {
1220
fn number(&self) -> u32 {

objc_exception/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@ extern "C" {
2929
}
3030

3131
/// An opaque type representing any Objective-C object thrown as an exception.
32-
pub enum Exception {}
32+
///
33+
/// In the future this will be an [`extern type`][rfc-1861], if that gets
34+
/// stabilized.
35+
///
36+
/// [rfc-1861]: https://rust-lang.github.io/rfcs/1861-extern-types.html
37+
#[repr(C)]
38+
pub struct Exception {
39+
/// See the [Nomicon] for details on representing opaque structs.
40+
///
41+
/// [Nomicon]: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
42+
_priv: [u8; 0],
43+
}
3344

3445
/// Throws an Objective-C exception.
3546
/// The argument must be a pointer to an Objective-C object.

objc_foundation/src/macros.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#[macro_export]
22
macro_rules! object_struct {
33
($name:ident) => {
4+
// TODO: `extern type`
5+
#[repr(C)]
46
pub struct $name {
5-
_private: (),
7+
_private: [u8; 0],
68
}
79

810
unsafe impl ::objc::Message for $name {}

0 commit comments

Comments
 (0)