Skip to content

Commit 99988b4

Browse files
committed
Use simpler syntax for where bounds
1 parent 5aaae76 commit 99988b4

File tree

8 files changed

+46
-135
lines changed

8 files changed

+46
-135
lines changed

objc2/src/declare.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ pub trait MethodImplementation {
5656

5757
macro_rules! method_decl_impl {
5858
(-$s:ident, $r:ident, $f:ty, $($t:ident),*) => (
59-
impl<$s, $r $(, $t)*> MethodImplementation for $f
60-
where $s: Message, $r: Encode $(, $t: Encode)* {
59+
impl<$s, $r, $($t),*> MethodImplementation for $f
60+
where
61+
$s: Message,
62+
$r: Encode,
63+
$($t: Encode,)*
64+
{
6165
type Callee = $s;
6266
type Ret = $r;
6367
type Args = ($($t,)*);
@@ -68,8 +72,8 @@ macro_rules! method_decl_impl {
6872
}
6973
);
7074
($($t:ident),*) => (
71-
method_decl_impl!(-T, R, extern fn(&T, Sel $(, $t)*) -> R, $($t),*);
72-
method_decl_impl!(-T, R, extern fn(&mut T, Sel $(, $t)*) -> R, $($t),*);
75+
method_decl_impl!(-T, R, extern "C" fn(&T, Sel $(, $t)*) -> R, $($t),*);
76+
method_decl_impl!(-T, R, extern "C" fn(&mut T, Sel $(, $t)*) -> R, $($t),*);
7377
);
7478
}
7579

objc2_block/src/lib.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,24 @@ macro_rules! concrete_block_impl {
231231
);
232232
($f:ident, $($a:ident : $t:ident),*) => (
233233
impl<$($t: Encode,)* R: Encode, X> IntoConcreteBlock<($($t,)*)> for X
234-
where X: Fn($($t,)*) -> R {
234+
where
235+
X: Fn($($t,)*) -> R,
236+
{
235237
type Ret = R;
236238

237239
fn into_concrete_block(self) -> ConcreteBlock<($($t,)*), R, X> {
238240
unsafe extern fn $f<$($t,)* R, X>(
239-
block_ptr: *mut ConcreteBlock<($($t,)*), R, X>
240-
$(, $a: $t)*) -> R
241-
where X: Fn($($t,)*) -> R {
241+
block_ptr: *mut ConcreteBlock<($($t,)*), R, X>
242+
$(, $a: $t)*
243+
) -> R
244+
where
245+
X: Fn($($t,)*) -> R
246+
{
242247
let block = &*block_ptr;
243248
(block.closure)($($a),*)
244249
}
245250

246-
let f: unsafe extern fn(*mut ConcreteBlock<($($t,)*), R, X> $(, $a: $t)*) -> R = $f;
251+
let f: unsafe extern "C" fn(*mut ConcreteBlock<($($t,)*), R, X> $(, $a: $t)*) -> R = $f;
247252
unsafe {
248253
ConcreteBlock::with_invoke(mem::transmute(f), self)
249254
}
@@ -397,10 +402,7 @@ impl<A, R, F> ConcreteBlock<A, R, F> {
397402
}
398403
}
399404

400-
impl<A, R, F> ConcreteBlock<A, R, F>
401-
where
402-
F: 'static,
403-
{
405+
impl<A, R, F: 'static> ConcreteBlock<A, R, F> {
404406
/// Copy self onto the heap as an `RcBlock`.
405407
pub fn copy(self) -> RcBlock<A, R> {
406408
unsafe {
@@ -415,10 +417,7 @@ where
415417
}
416418
}
417419

418-
impl<A, R, F> Clone for ConcreteBlock<A, R, F>
419-
where
420-
F: Clone,
421-
{
420+
impl<A, R, F: Clone> Clone for ConcreteBlock<A, R, F> {
422421
fn clone(&self) -> Self {
423422
unsafe {
424423
ConcreteBlock::with_invoke(mem::transmute(self.base.invoke), self.closure.clone())

objc2_foundation/src/array.rs

Lines changed: 14 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ unsafe impl Encode for NSRange {
7171
Encoding::Struct("_NSRange", &[usize::ENCODING, usize::ENCODING]);
7272
}
7373

74-
unsafe fn from_refs<A>(refs: &[&A::Item]) -> Id<A, A::Ownership>
75-
where
76-
A: INSArray,
77-
{
74+
unsafe fn from_refs<A: INSArray>(refs: &[&A::Item]) -> Id<A, A::Ownership> {
7875
let cls = A::class();
7976
let obj: *mut A = msg_send![cls, alloc];
8077
let obj: *mut A = msg_send![
@@ -197,54 +194,32 @@ pub struct NSArray<T, O: Ownership = Owned> {
197194

198195
object_impl!(NSArray<T, O: Ownership>);
199196

200-
impl<T, O> INSObject for NSArray<T, O>
201-
where
202-
T: INSObject,
203-
O: Ownership,
204-
{
197+
impl<T: INSObject, O: Ownership> INSObject for NSArray<T, O> {
205198
type Ownership = Shared;
206199

207200
fn class() -> &'static Class {
208201
class!(NSArray)
209202
}
210203
}
211204

212-
impl<T, O> INSArray for NSArray<T, O>
213-
where
214-
T: INSObject,
215-
O: Ownership,
216-
{
205+
impl<T: INSObject, O: Ownership> INSArray for NSArray<T, O> {
217206
type Item = T;
218207
type Own = O;
219208
}
220209

221-
impl<T> INSCopying for NSArray<T, Shared>
222-
where
223-
T: INSObject,
224-
{
210+
impl<T: INSObject> INSCopying for NSArray<T, Shared> {
225211
type Output = NSSharedArray<T>;
226212
}
227213

228-
impl<T> INSMutableCopying for NSArray<T, Shared>
229-
where
230-
T: INSObject,
231-
{
214+
impl<T: INSObject> INSMutableCopying for NSArray<T, Shared> {
232215
type Output = NSMutableSharedArray<T>;
233216
}
234217

235-
impl<T, O> INSFastEnumeration for NSArray<T, O>
236-
where
237-
T: INSObject,
238-
O: Ownership,
239-
{
218+
impl<T: INSObject, O: Ownership> INSFastEnumeration for NSArray<T, O> {
240219
type Item = T;
241220
}
242221

243-
impl<T, O> Index<usize> for NSArray<T, O>
244-
where
245-
T: INSObject,
246-
O: Ownership,
247-
{
222+
impl<T: INSObject, O: Ownership> Index<usize> for NSArray<T, O> {
248223
type Output = T;
249224

250225
fn index(&self, index: usize) -> &T {
@@ -352,61 +327,34 @@ pub struct NSMutableArray<T, O: Ownership = Owned> {
352327

353328
object_impl!(NSMutableArray<T, O: Ownership>);
354329

355-
impl<T, O> INSObject for NSMutableArray<T, O>
356-
where
357-
T: INSObject,
358-
O: Ownership,
359-
{
330+
impl<T: INSObject, O: Ownership> INSObject for NSMutableArray<T, O> {
360331
type Ownership = Owned;
361332

362333
fn class() -> &'static Class {
363334
class!(NSMutableArray)
364335
}
365336
}
366337

367-
impl<T, O> INSArray for NSMutableArray<T, O>
368-
where
369-
T: INSObject,
370-
O: Ownership,
371-
{
338+
impl<T: INSObject, O: Ownership> INSArray for NSMutableArray<T, O> {
372339
type Item = T;
373340
type Own = O;
374341
}
375342

376-
impl<T, O> INSMutableArray for NSMutableArray<T, O>
377-
where
378-
T: INSObject,
379-
O: Ownership,
380-
{
381-
}
343+
impl<T: INSObject, O: Ownership> INSMutableArray for NSMutableArray<T, O> {}
382344

383-
impl<T> INSCopying for NSMutableArray<T, Shared>
384-
where
385-
T: INSObject,
386-
{
345+
impl<T: INSObject> INSCopying for NSMutableArray<T, Shared> {
387346
type Output = NSSharedArray<T>;
388347
}
389348

390-
impl<T> INSMutableCopying for NSMutableArray<T, Shared>
391-
where
392-
T: INSObject,
393-
{
349+
impl<T: INSObject> INSMutableCopying for NSMutableArray<T, Shared> {
394350
type Output = NSMutableSharedArray<T>;
395351
}
396352

397-
impl<T, O> INSFastEnumeration for NSMutableArray<T, O>
398-
where
399-
T: INSObject,
400-
O: Ownership,
401-
{
353+
impl<T: INSObject, O: Ownership> INSFastEnumeration for NSMutableArray<T, O> {
402354
type Item = T;
403355
}
404356

405-
impl<T, O> Index<usize> for NSMutableArray<T, O>
406-
where
407-
T: INSObject,
408-
O: Ownership,
409-
{
357+
impl<T: INSObject, O: Ownership> Index<usize> for NSMutableArray<T, O> {
410358
type Output = T;
411359

412360
fn index(&self, index: usize) -> &T {

objc2_foundation/src/dictionary.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,41 +137,25 @@ pub struct NSDictionary<K, V> {
137137

138138
object_impl!(NSDictionary<K, V>);
139139

140-
impl<K, V> INSObject for NSDictionary<K, V>
141-
where
142-
K: INSObject,
143-
V: INSObject,
144-
{
140+
impl<K: INSObject, V: INSObject> INSObject for NSDictionary<K, V> {
145141
type Ownership = Shared;
146142

147143
fn class() -> &'static Class {
148144
class!(NSDictionary)
149145
}
150146
}
151147

152-
impl<K, V> INSDictionary for NSDictionary<K, V>
153-
where
154-
K: INSObject,
155-
V: INSObject,
156-
{
148+
impl<K: INSObject, V: INSObject> INSDictionary for NSDictionary<K, V> {
157149
type Key = K;
158150
type Value = V;
159151
type Own = Owned;
160152
}
161153

162-
impl<K, V> INSFastEnumeration for NSDictionary<K, V>
163-
where
164-
K: INSObject,
165-
V: INSObject,
166-
{
154+
impl<K: INSObject, V: INSObject> INSFastEnumeration for NSDictionary<K, V> {
167155
type Item = K;
168156
}
169157

170-
impl<'a, K, V> Index<&'a K> for NSDictionary<K, V>
171-
where
172-
K: INSObject,
173-
V: INSObject,
174-
{
158+
impl<'a, K: INSObject, V: INSObject> Index<&'a K> for NSDictionary<K, V> {
175159
type Output = V;
176160

177161
fn index(&self, index: &K) -> &V {

objc2_foundation/src/enumerator.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,12 @@ use objc2::{msg_send, Encode, Encoding, RefEncode};
1111

1212
use super::INSObject;
1313

14-
pub struct NSEnumerator<'a, T>
15-
where
16-
T: INSObject,
17-
{
14+
pub struct NSEnumerator<'a, T: INSObject> {
1815
id: Id<Object, Owned>,
1916
item: PhantomData<&'a T>,
2017
}
2118

22-
impl<'a, T> NSEnumerator<'a, T>
23-
where
24-
T: INSObject,
25-
{
19+
impl<'a, T: INSObject> NSEnumerator<'a, T> {
2620
/// TODO
2721
///
2822
/// # Safety
@@ -37,10 +31,7 @@ where
3731
}
3832
}
3933

40-
impl<'a, T> Iterator for NSEnumerator<'a, T>
41-
where
42-
T: INSObject,
43-
{
34+
impl<'a, T: INSObject> Iterator for NSEnumerator<'a, T> {
4435
type Item = &'a T;
4536

4637
fn next(&mut self) -> Option<&'a T> {

objc2_foundation/src/macros.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ macro_rules! object_struct {
3030
impl ::core::cmp::Eq for $name {}
3131

3232
impl ::core::hash::Hash for $name {
33-
fn hash<H>(&self, state: &mut H)
34-
where
35-
H: ::core::hash::Hasher,
36-
{
33+
fn hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
3734
use $crate::INSObject;
3835
self.hash_code().hash(state);
3936
}

objc2_foundation/src/object.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ pub trait INSObject: Any + Sized + Message {
3131
unsafe { msg_send![self, hash] }
3232
}
3333

34-
fn is_equal<T>(&self, other: &T) -> bool
35-
where
36-
T: INSObject,
37-
{
34+
fn is_equal<T: INSObject>(&self, other: &T) -> bool {
3835
let result: Bool = unsafe { msg_send![self, isEqual: other] };
3936
result.is_true()
4037
}

objc2_foundation/src/value.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,19 @@ pub struct NSValue<T> {
5959

6060
object_impl!(NSValue<T>);
6161

62-
impl<T> INSObject for NSValue<T>
63-
where
64-
T: Any,
65-
{
62+
impl<T: Any> INSObject for NSValue<T> {
6663
type Ownership = Shared;
6764

6865
fn class() -> &'static Class {
6966
class!(NSValue)
7067
}
7168
}
7269

73-
impl<T> INSValue for NSValue<T>
74-
where
75-
T: Any + Copy + Encode,
76-
{
70+
impl<T: Any + Copy + Encode> INSValue for NSValue<T> {
7771
type Value = T;
7872
}
7973

80-
impl<T> INSCopying for NSValue<T>
81-
where
82-
T: Any,
83-
{
74+
impl<T: Any> INSCopying for NSValue<T> {
8475
type Output = NSValue<T>;
8576
}
8677

0 commit comments

Comments
 (0)