Skip to content

Commit d66a381

Browse files
committed
Change the object macro syntax a bit
1 parent 76cd61a commit d66a381

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

objc2-foundation/src/array.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ object!(
169169
/// TODO: Can we make it impossible? Should we?
170170
///
171171
/// What about `Id<NSArray<T, Shared>, Owned>`?
172-
unsafe pub struct<T: INSObject, O: Ownership> NSArray<T, O: Ownership> {
172+
unsafe pub struct NSArray<T, O: Ownership> {
173173
item: PhantomData<Id<T, O>>,
174174
}
175+
impl where T: INSObject
175176
);
176177

177178
unsafe impl<T: INSObject, O: Ownership> INSArray for NSArray<T, O> {
@@ -314,9 +315,10 @@ pub unsafe trait INSMutableArray: INSArray {
314315
}
315316

316317
object!(
317-
unsafe pub struct<T: INSObject, O: Ownership> NSMutableArray<T, O: Ownership> {
318+
unsafe pub struct NSMutableArray<T, O: Ownership> {
318319
item: PhantomData<Id<T, O>>,
319320
}
321+
impl where T: INSObject
320322
);
321323

322324
unsafe impl<T: INSObject, O: Ownership> INSArray for NSMutableArray<T, O> {

objc2-foundation/src/dictionary.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,13 @@ pub unsafe trait INSDictionary: INSObject {
139139
}
140140

141141
object!(
142-
unsafe pub struct<K: INSObject, V: INSObject> NSDictionary<K, V> {
142+
unsafe pub struct NSDictionary<K, V> {
143143
key: PhantomData<Id<K, Shared>>,
144144
obj: PhantomData<Id<V, Owned>>,
145145
}
146+
impl where
147+
K: INSObject,
148+
V: INSObject,
146149
);
147150

148151
impl<K: INSObject, V: INSObject> NSDictionary<K, V> {

objc2-foundation/src/macros.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,56 @@
77
/// example: `NSAutoreleasePool` does not have this). Finally the ownership
88
/// must be correct for this class.
99
macro_rules! object {
10-
($(#[$m:meta])* unsafe $v:vis struct $name:ident) => {
11-
object!($(#[$m])* unsafe $v struct<()> $name<> {});
10+
(
11+
$(#[$m:meta])*
12+
unsafe $v:vis struct $name:ident
13+
) => {
14+
object!($(#[$m])* unsafe $v struct $name<> {});
1215
};
13-
($(#[$m:meta])* unsafe $v:vis struct<$($t:ident $(: $b:ident)?),+> $name:ident<$($t2:ident $(: $b2:ident)?),+> {
14-
$($p:ident: $pty:ty,)*
15-
}) => {
16-
object!($(#[$m])* unsafe $v struct<($($t $(: $b)?),+)> $name<$($t2 $(: $b2)?),+> {
17-
$($p: $pty,)*
18-
});
19-
};
20-
($(#[$m:meta])* unsafe $v:vis struct<($($t:tt)*)> $name:ident<$($t2:ident $(: $b2:ident)?),*> {
21-
$($p:ident: $pty:ty,)*
22-
}) => {
16+
(
17+
$(#[$m:meta])*
18+
unsafe $v:vis struct $name:ident<$($t:ident $(: $b:ident)?),*> {
19+
$($p:ident: $pty:ty,)*
20+
}
21+
$(impl where $($w:tt)+)?
22+
) => {
2323
// TODO: `extern type`
2424
$(#[$m])*
2525
#[repr(C)]
26-
$v struct $name<$($t2 $(: $b2)?),*> {
26+
$v struct $name<$($t $(: $b)?),*> {
2727
_private: [u8; 0],
2828
$($p: $pty),*
2929
}
3030

31-
unsafe impl<$($t)*> ::objc2::Message for $name<$($t2),*> { }
31+
unsafe impl<$($t $(: $b)?),*> ::objc2::Message for $name<$($t),*> { }
3232

33-
unsafe impl<$($t)*> ::objc2::RefEncode for $name<$($t2),*> {
33+
unsafe impl<$($t $(: $b)?),*> ::objc2::RefEncode for $name<$($t),*> {
3434
const ENCODING_REF: ::objc2::Encoding<'static> = ::objc2::Encoding::Object;
3535
}
3636

37-
unsafe impl<$($t)*> $crate::INSObject for $name<$($t2),*> {
37+
unsafe impl<$($t $(: $b)?),*> $crate::INSObject for $name<$($t),*> {
3838
fn class() -> &'static ::objc2::runtime::Class {
3939
::objc2::class!($name)
4040
}
4141
}
4242

43-
impl<$($t)*> ::core::cmp::PartialEq for $name<$($t2),*> {
43+
impl<$($t $(: $b)?),*> ::core::cmp::PartialEq for $name<$($t),*> {
4444
fn eq(&self, other: &Self) -> bool {
4545
use $crate::INSObject;
4646
self.is_equal(other)
4747
}
4848
}
4949

50-
impl<$($t)*> ::core::cmp::Eq for $name<$($t2),*> {}
50+
impl<$($t $(: $b)?),*> ::core::cmp::Eq for $name<$($t),*> {}
5151

52-
impl<$($t)*> ::core::hash::Hash for $name<$($t2),*> {
52+
impl<$($t $(: $b)?),*> ::core::hash::Hash for $name<$($t),*> {
5353
fn hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
5454
use $crate::INSObject;
5555
self.hash_code().hash(state);
5656
}
5757
}
5858

59-
impl<$($t)*> ::core::fmt::Debug for $name<$($t2),*> {
59+
impl<$($t $(: $b)?),*> ::core::fmt::Debug for $name<$($t),*> {
6060
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
6161
use $crate::{INSObject, INSString};
6262
::objc2::rc::autoreleasepool(|pool| {

objc2-foundation/src/value.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ pub unsafe trait INSValue: INSObject {
7070
}
7171

7272
object!(
73-
unsafe pub struct<(T: 'static)> NSValue<T> {
73+
unsafe pub struct NSValue<T> {
7474
value: PhantomData<T>,
7575
}
76+
impl where T: 'static
7677
);
7778

7879
unsafe impl<T: 'static + Copy + Encode> INSValue for NSValue<T> {

0 commit comments

Comments
 (0)