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 #[repr(transparent)] 13 #[derive(Debug, Copy, Clone)] 14 pub struct Foo(pub id); 15 impl std::ops::Deref for Foo { 16 type Target = objc::runtime::Object; deref(&self) -> &Self::Target17 fn deref(&self) -> &Self::Target { 18 unsafe { &*self.0 } 19 } 20 } 21 unsafe impl objc::Message for Foo {} 22 impl Foo { alloc() -> Self23 pub fn alloc() -> Self { 24 Self(unsafe { msg_send!(class!(Foo), alloc) }) 25 } 26 } 27 impl IFoo for Foo {} 28 pub trait IFoo: Sized + std::ops::Deref { foo(&self) where <Self as std::ops::Deref>::Target: objc::Message + Sized,29 unsafe fn foo(&self) 30 where 31 <Self as std::ops::Deref>::Target: objc::Message + Sized, 32 { 33 msg_send!(*self, foo) 34 } class_foo() where <Self as std::ops::Deref>::Target: objc::Message + Sized,35 unsafe fn class_foo() 36 where 37 <Self as std::ops::Deref>::Target: objc::Message + Sized, 38 { 39 msg_send!(class!(Foo), foo) 40 } 41 } 42