1 #![allow( 2 dead_code, 3 non_snake_case, 4 non_camel_case_types, 5 non_upper_case_globals 6 )] 7 #![cfg(target_os = "macos")] 8 9 use objc::{self, class, msg_send, sel, sel_impl}; 10 #[allow(non_camel_case_types)] 11 pub type id = *mut objc::runtime::Object; 12 extern "C" { 13 pub static mut fooVar: Foo; 14 } 15 #[repr(transparent)] 16 #[derive(Debug, Copy, Clone)] 17 pub struct Foo(pub id); 18 impl std::ops::Deref for Foo { 19 type Target = objc::runtime::Object; deref(&self) -> &Self::Target20 fn deref(&self) -> &Self::Target { 21 unsafe { &*self.0 } 22 } 23 } 24 unsafe impl objc::Message for Foo {} 25 impl Foo { alloc() -> Self26 pub fn alloc() -> Self { 27 Self(unsafe { msg_send!(class!(Foo), alloc) }) 28 } 29 } 30 impl IFoo for Foo {} 31 pub trait IFoo: Sized + std::ops::Deref { method(&self) where <Self as std::ops::Deref>::Target: objc::Message + Sized,32 unsafe fn method(&self) 33 where 34 <Self as std::ops::Deref>::Target: objc::Message + Sized, 35 { 36 msg_send!(*self, method) 37 } 38 } 39