objc_foundation/
macros.rs1#[macro_export]
2macro_rules! object_struct {
3 ($name:ident) => (
4 pub struct $name {
5 _private: (),
6 }
7
8 unsafe impl ::objc::Message for $name { }
9
10 impl $crate::INSObject for $name {
11 fn class() -> &'static ::objc::runtime::Class {
12 let name = stringify!($name);
13 match ::objc::runtime::Class::get(name) {
14 Some(cls) => cls,
15 None => panic!("Class {} not found", name),
16 }
17 }
18 }
19
20 impl ::std::cmp::PartialEq for $name {
21 fn eq(&self, other: &Self) -> bool {
22 use $crate::INSObject;
23 self.is_equal(other)
24 }
25 }
26
27 impl ::std::cmp::Eq for $name { }
28
29 impl ::std::hash::Hash for $name {
30 fn hash<H>(&self, state: &mut H) where H: ::std::hash::Hasher {
31 use $crate::INSObject;
32 self.hash_code().hash(state);
33 }
34 }
35
36 impl ::std::fmt::Debug for $name {
37 fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
38 use $crate::{INSObject, INSString};
39 ::std::fmt::Debug::fmt(self.description().as_str(), f)
40 }
41 }
42 );
43}
44
45macro_rules! object_impl {
46 ($name:ident) => (
47 object_impl!($name,);
48 );
49 ($name:ident<$($t:ident),+>) => (
50 object_impl!($name, $($t),+);
51 );
52 ($name:ident, $($t:ident),*) => (
53 unsafe impl<$($t),*> ::objc::Message for $name<$($t),*> { }
54 );
55}