summaryrefslogtreecommitdiff
path: root/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs')
-rw-r--r--bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs b/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs
new file mode 100644
index 00000000..f5f80e2e
--- /dev/null
+++ b/bindgen-tests/tests/expectations/tests/objc_protocol_inheritance.rs
@@ -0,0 +1,66 @@
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+#![cfg(target_os = "macos")]
+
+use objc::{self, class, msg_send, sel, sel_impl};
+#[allow(non_camel_case_types)]
+pub type id = *mut objc::runtime::Object;
+pub trait PFoo: Sized + std::ops::Deref {}
+#[repr(transparent)]
+#[derive(Debug, Copy, Clone)]
+pub struct Foo(pub id);
+impl std::ops::Deref for Foo {
+ type Target = objc::runtime::Object;
+ fn deref(&self) -> &Self::Target {
+ unsafe { &*self.0 }
+ }
+}
+unsafe impl objc::Message for Foo {}
+impl Foo {
+ pub fn alloc() -> Self {
+ Self(unsafe { msg_send!(class!(Foo), alloc) })
+ }
+}
+impl PFoo for Foo {}
+impl IFoo for Foo {}
+pub trait IFoo: Sized + std::ops::Deref {}
+#[repr(transparent)]
+#[derive(Debug, Copy, Clone)]
+pub struct Bar(pub id);
+impl std::ops::Deref for Bar {
+ type Target = objc::runtime::Object;
+ fn deref(&self) -> &Self::Target {
+ unsafe { &*self.0 }
+ }
+}
+unsafe impl objc::Message for Bar {}
+impl Bar {
+ pub fn alloc() -> Self {
+ Self(unsafe { msg_send!(class!(Bar), alloc) })
+ }
+}
+impl IFoo for Bar {}
+impl PFoo for Bar {}
+impl From<Bar> for Foo {
+ fn from(child: Bar) -> Foo {
+ Foo(child.0)
+ }
+}
+impl std::convert::TryFrom<Foo> for Bar {
+ type Error = &'static str;
+ fn try_from(parent: Foo) -> Result<Bar, Self::Error> {
+ let is_kind_of: bool =
+ unsafe { msg_send!(parent, isKindOfClass: class!(Bar)) };
+ if is_kind_of {
+ Ok(Bar(parent.0))
+ } else {
+ Err("This Foo cannot be downcasted to Bar")
+ }
+ }
+}
+impl IBar for Bar {}
+pub trait IBar: Sized + std::ops::Deref {}