-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmacros.rs
51 lines (44 loc) · 1.34 KB
/
macros.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#[macro_export]
macro_rules! object_struct {
($name:ident) => (
pub struct $name {
_private: (),
}
unsafe impl ::objc::Message for $name { }
impl $crate::INSObject for $name {
fn class() -> &'static ::objc::runtime::Class {
class!($name)
}
}
impl ::std::cmp::PartialEq for $name {
fn eq(&self, other: &Self) -> bool {
use $crate::INSObject;
self.is_equal(other)
}
}
impl ::std::cmp::Eq for $name { }
impl ::std::hash::Hash for $name {
fn hash<H>(&self, state: &mut H) where H: ::std::hash::Hasher {
use $crate::INSObject;
self.hash_code().hash(state);
}
}
impl ::std::fmt::Debug for $name {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
use $crate::{INSObject, INSString};
::std::fmt::Debug::fmt(self.description().as_str(), f)
}
}
);
}
macro_rules! object_impl {
($name:ident) => (
object_impl!($name,);
);
($name:ident<$($t:ident),+>) => (
object_impl!($name, $($t),+);
);
($name:ident, $($t:ident),*) => (
unsafe impl<$($t),*> ::objc::Message for $name<$($t),*> { }
);
}