Skip to content

Commit 490bb35

Browse files
committed
Manually format usage of msg_send!
Rustfmt can't do this for us
1 parent 77f1358 commit 490bb35

File tree

12 files changed

+86
-44
lines changed

12 files changed

+86
-44
lines changed

objc2/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let cls = class!(NSObject);
1919
unsafe {
2020
let obj: *mut Object = msg_send![cls, new];
2121
let hash: usize = msg_send![obj, hash];
22-
let is_kind: BOOL = msg_send![obj, isKindOfClass:cls];
22+
let is_kind: BOOL = msg_send![obj, isKindOfClass: cls];
2323
// Even void methods must have their return type annotated
2424
let _: () = msg_send![obj, release];
2525
}

objc2/src/declare.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ mod tests {
372372
// Registering the custom class is in test_utils
373373
let obj = test_utils::custom_object();
374374
unsafe {
375-
let _: () = msg_send![obj, setFoo:13u32];
375+
let _: () = msg_send![obj, setFoo: 13u32];
376376
let result: u32 = msg_send![obj, foo];
377377
assert!(result == 13);
378378
}

objc2/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Objective-C objects can be messaged using the [`msg_send!`](macro.msg_send!.html
1212
let cls = class!(NSObject);
1313
let obj: *mut Object = msg_send![cls, new];
1414
let hash: usize = msg_send![obj, hash];
15-
let is_kind: BOOL = msg_send![obj, isKindOfClass:cls];
15+
let is_kind: BOOL = msg_send![obj, isKindOfClass: cls];
1616
// Even void methods must have their return type annotated
1717
let _: () = msg_send![obj, release];
1818
# }

objc2/src/message/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ mod tests {
383383
fn test_send_message() {
384384
let obj = test_utils::custom_object();
385385
let result: u32 = unsafe {
386-
let _: () = msg_send![obj, setFoo:4u32];
386+
let _: () = msg_send![obj, setFoo: 4u32];
387387
msg_send![obj, foo]
388388
};
389389
assert!(result == 4);
@@ -421,7 +421,7 @@ mod tests {
421421
let obj = test_utils::custom_subclass_object();
422422
let superclass = test_utils::custom_class();
423423
unsafe {
424-
let _: () = msg_send![obj, setFoo:4u32];
424+
let _: () = msg_send![obj, setFoo: 4u32];
425425
let foo: u32 = msg_send![super(obj, superclass), foo];
426426
assert!(foo == 4);
427427

objc2/src/runtime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ mod tests {
533533
#[test]
534534
fn test_protocol_method() {
535535
let class = test_utils::custom_class();
536-
let result: i32 = unsafe { msg_send![class, addNumber:1 toNumber:2] };
536+
let result: i32 = unsafe { msg_send![class, addNumber: 1, toNumber: 2] };
537537
assert_eq!(result, 3);
538538
}
539539

objc2_foundation/examples/custom_class.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn main() {
8282
});
8383

8484
unsafe {
85-
let _: () = msg_send![obj, setNumber:12u32];
85+
let _: () = msg_send![obj, setNumber: 12u32];
8686
}
8787
println!("Number: {}", obj.number());
8888
}

objc2_foundation/src/array.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ where
7777
{
7878
let cls = A::class();
7979
let obj: *mut A = msg_send![cls, alloc];
80-
let obj: *mut A = msg_send![obj, initWithObjects:refs.as_ptr()
81-
count:refs.len()];
80+
let obj: *mut A = msg_send![
81+
obj,
82+
initWithObjects: refs.as_ptr(),
83+
count: refs.len(),
84+
];
8285
Id::new(NonNull::new_unchecked(obj))
8386
}
8487

@@ -135,7 +138,7 @@ pub trait INSArray: INSObject {
135138
let range = NSRange::from_range(range);
136139
let mut vec = Vec::with_capacity(range.length);
137140
unsafe {
138-
let _: () = msg_send![self, getObjects:vec.as_ptr() range:range];
141+
let _: () = msg_send![self, getObjects: vec.as_ptr(), range: range];
139142
vec.set_len(range.length);
140143
}
141144
vec
@@ -254,13 +257,13 @@ pub type NSSharedArray<T> = NSArray<T, Shared>;
254257
pub trait INSMutableArray: INSArray {
255258
fn add_object(&mut self, obj: Id<Self::Item, Self::Own>) {
256259
unsafe {
257-
let _: () = msg_send![self, addObject:&*obj];
260+
let _: () = msg_send![self, addObject: &*obj];
258261
}
259262
}
260263

261264
fn insert_object_at(&mut self, index: usize, obj: Id<Self::Item, Self::Own>) {
262265
unsafe {
263-
let _: () = msg_send![self, insertObject:&*obj atIndex:index];
266+
let _: () = msg_send![self, insertObject: &*obj, atIndex: index];
264267
}
265268
}
266269

@@ -274,8 +277,11 @@ pub trait INSMutableArray: INSArray {
274277
Id::retain(obj.into())
275278
};
276279
unsafe {
277-
let _: () = msg_send![self, replaceObjectAtIndex:index
278-
withObject:&*obj];
280+
let _: () = msg_send![
281+
self,
282+
replaceObjectAtIndex: index,
283+
withObject: &*obj,
284+
];
279285
}
280286
old_obj
281287
}
@@ -333,7 +339,7 @@ pub trait INSMutableArray: INSArray {
333339
let context = &mut closure as *mut F as *mut c_void;
334340

335341
unsafe {
336-
let _: () = msg_send![self, sortUsingFunction:f context:context];
342+
let _: () = msg_send![self, sortUsingFunction: f, context: context];
337343
}
338344
// Keep the closure alive until the function has run.
339345
drop(closure);

objc2_foundation/src/data.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ pub trait INSData: INSObject {
3535
let bytes_ptr = bytes.as_ptr() as *const c_void;
3636
unsafe {
3737
let obj: *mut Self = msg_send![cls, alloc];
38-
let obj: *mut Self = msg_send![obj, initWithBytes:bytes_ptr
39-
length:bytes.len()];
38+
let obj: *mut Self = msg_send![
39+
obj,
40+
initWithBytes: bytes_ptr,
41+
length: bytes.len(),
42+
];
4043
Id::new(NonNull::new_unchecked(obj))
4144
}
4245
}
@@ -56,9 +59,12 @@ pub trait INSData: INSObject {
5659
let cls = Self::class();
5760
unsafe {
5861
let obj: *mut Self = msg_send![cls, alloc];
59-
let obj: *mut Self = msg_send![obj, initWithBytesNoCopy:bytes_ptr
60-
length:bytes.len()
61-
deallocator:dealloc];
62+
let obj: *mut Self = msg_send![
63+
obj,
64+
initWithBytesNoCopy: bytes_ptr,
65+
length: bytes.len(),
66+
deallocator: dealloc,
67+
];
6268
core::mem::forget(bytes);
6369
Id::new(NonNull::new_unchecked(obj))
6470
}
@@ -98,18 +104,24 @@ pub trait INSMutableData: INSData {
98104
fn append(&mut self, bytes: &[u8]) {
99105
let bytes_ptr = bytes.as_ptr() as *const c_void;
100106
unsafe {
101-
let _: () = msg_send![self, appendBytes:bytes_ptr
102-
length:bytes.len()];
107+
let _: () = msg_send![
108+
self,
109+
appendBytes: bytes_ptr,
110+
length:bytes.len(),
111+
];
103112
}
104113
}
105114

106115
fn replace_range(&mut self, range: Range<usize>, bytes: &[u8]) {
107116
let range = NSRange::from_range(range);
108117
let bytes_ptr = bytes.as_ptr() as *const c_void;
109118
unsafe {
110-
let _: () = msg_send![self, replaceBytesInRange:range
111-
withBytes:bytes_ptr
112-
length:bytes.len()];
119+
let _: () = msg_send![
120+
self,
121+
replaceBytesInRange:range,
122+
withBytes:bytes_ptr,
123+
length:bytes.len(),
124+
];
113125
}
114126
}
115127

objc2_foundation/src/dictionary.rs

+26-11
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ where
1818
let cls = D::class();
1919
let count = min(keys.len(), vals.len());
2020
let obj: *mut D = msg_send![cls, alloc];
21-
let obj: *mut D = msg_send![obj, initWithObjects:vals.as_ptr()
22-
forKeys:keys.as_ptr()
23-
count:count];
21+
let obj: *mut D = msg_send![
22+
obj,
23+
initWithObjects: vals.as_ptr(),
24+
forKeys: keys.as_ptr(),
25+
count: count,
26+
];
2427
Id::new(NonNull::new_unchecked(obj))
2528
}
2629

@@ -48,8 +51,11 @@ pub trait INSDictionary: INSObject {
4851
let len = self.count();
4952
let mut keys = Vec::with_capacity(len);
5053
unsafe {
51-
let _: () = msg_send![self, getObjects:ptr::null_mut::<&Self::Value>()
52-
andKeys:keys.as_mut_ptr()];
54+
let _: () = msg_send![
55+
self,
56+
getObjects: ptr::null_mut::<&Self::Value>(),
57+
andKeys: keys.as_mut_ptr(),
58+
];
5359
keys.set_len(len);
5460
}
5561
keys
@@ -59,8 +65,11 @@ pub trait INSDictionary: INSObject {
5965
let len = self.count();
6066
let mut vals = Vec::with_capacity(len);
6167
unsafe {
62-
let _: () = msg_send![self, getObjects:vals.as_mut_ptr()
63-
andKeys:ptr::null_mut::<&Self::Key>()];
68+
let _: () = msg_send![
69+
self,
70+
getObjects: vals.as_mut_ptr(),
71+
andKeys: ptr::null_mut::<&Self::Key>(),
72+
];
6473
vals.set_len(len);
6574
}
6675
vals
@@ -71,8 +80,11 @@ pub trait INSDictionary: INSObject {
7180
let mut keys = Vec::with_capacity(len);
7281
let mut objs = Vec::with_capacity(len);
7382
unsafe {
74-
let _: () = msg_send![self, getObjects:objs.as_mut_ptr()
75-
andKeys:keys.as_mut_ptr()];
83+
let _: () = msg_send![
84+
self,
85+
getObjects: objs.as_mut_ptr(),
86+
andKeys: keys.as_mut_ptr(),
87+
];
7688
keys.set_len(len);
7789
objs.set_len(len);
7890
}
@@ -100,7 +112,10 @@ pub trait INSDictionary: INSObject {
100112
}
101113
}
102114

103-
fn from_keys_and_objects<T>(keys: &[&T], vals: Vec<Id<Self::Value, Self::Own>>) -> Id<Self, Owned>
115+
fn from_keys_and_objects<T>(
116+
keys: &[&T],
117+
vals: Vec<Id<Self::Value, Self::Own>>,
118+
) -> Id<Self, Owned>
104119
where
105120
T: INSCopying<Output = Self::Key>,
106121
{
@@ -166,7 +181,7 @@ where
166181
#[cfg(test)]
167182
mod tests {
168183
use alloc::vec;
169-
use objc2::rc::{Owned, Id};
184+
use objc2::rc::{Id, Owned};
170185

171186
use super::{INSDictionary, NSDictionary};
172187
use crate::{INSArray, INSObject, INSString, NSObject, NSString};

objc2_foundation/src/enumerator.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ fn enumerate<'a, 'b: 'a, C: INSFastEnumeration>(
9595
let count: usize = unsafe {
9696
// Reborrow state so that we don't move it
9797
let state = &mut *state;
98-
msg_send![object, countByEnumeratingWithState:state
99-
objects:buf.as_mut_ptr()
100-
count:buf.len()]
98+
msg_send![
99+
object,
100+
countByEnumeratingWithState: state,
101+
objects: buf.as_mut_ptr(),
102+
count: buf.len(),
103+
]
101104
};
102105

103106
if count > 0 {

objc2_foundation/src/string.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ pub trait INSString: INSObject {
6363
let bytes = string.as_ptr() as *const c_void;
6464
unsafe {
6565
let obj: *mut Self = msg_send![cls, alloc];
66-
let obj: *mut Self = msg_send![obj, initWithBytes:bytes
67-
length:string.len()
68-
encoding:UTF8_ENCODING];
66+
let obj: *mut Self = msg_send![
67+
obj,
68+
initWithBytes: bytes,
69+
length: string.len(),
70+
encoding: UTF8_ENCODING,
71+
];
6972
Id::new(NonNull::new_unchecked(obj))
7073
}
7174
}

objc2_foundation/src/value.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ pub trait INSValue: INSObject {
4343
let encoding = CString::new(Self::Value::ENCODING.to_string()).unwrap();
4444
unsafe {
4545
let obj: *mut Self = msg_send![cls, alloc];
46-
let obj: *mut Self = msg_send![obj, initWithBytes:bytes
47-
objCType:encoding.as_ptr()];
46+
let obj: *mut Self = msg_send![
47+
obj,
48+
initWithBytes: bytes,
49+
objCType: encoding.as_ptr(),
50+
];
4851
Id::new(NonNull::new_unchecked(obj))
4952
}
5053
}

0 commit comments

Comments
 (0)