diff --git a/objc2/README.md b/objc2/README.md index 2e3af7584..12bf52be4 100644 --- a/objc2/README.md +++ b/objc2/README.md @@ -19,7 +19,7 @@ let cls = class!(NSObject); unsafe { let obj: *mut Object = msg_send![cls, new]; let hash: usize = msg_send![obj, hash]; - let is_kind: BOOL = msg_send![obj, isKindOfClass:cls]; + let is_kind: BOOL = msg_send![obj, isKindOfClass: cls]; // Even void methods must have their return type annotated let _: () = msg_send![obj, release]; } diff --git a/objc2/src/declare.rs b/objc2/src/declare.rs index f2ab27497..c6c2506a8 100644 --- a/objc2/src/declare.rs +++ b/objc2/src/declare.rs @@ -372,7 +372,7 @@ mod tests { // Registering the custom class is in test_utils let obj = test_utils::custom_object(); unsafe { - let _: () = msg_send![obj, setFoo:13u32]; + let _: () = msg_send![obj, setFoo: 13u32]; let result: u32 = msg_send![obj, foo]; assert!(result == 13); } diff --git a/objc2/src/lib.rs b/objc2/src/lib.rs index 53c3940f3..dcd49adad 100644 --- a/objc2/src/lib.rs +++ b/objc2/src/lib.rs @@ -12,7 +12,7 @@ Objective-C objects can be messaged using the [`msg_send!`](macro.msg_send!.html let cls = class!(NSObject); let obj: *mut Object = msg_send![cls, new]; let hash: usize = msg_send![obj, hash]; -let is_kind: BOOL = msg_send![obj, isKindOfClass:cls]; +let is_kind: BOOL = msg_send![obj, isKindOfClass: cls]; // Even void methods must have their return type annotated let _: () = msg_send![obj, release]; # } diff --git a/objc2/src/message/mod.rs b/objc2/src/message/mod.rs index 27bdd5008..e344d45eb 100644 --- a/objc2/src/message/mod.rs +++ b/objc2/src/message/mod.rs @@ -383,7 +383,7 @@ mod tests { fn test_send_message() { let obj = test_utils::custom_object(); let result: u32 = unsafe { - let _: () = msg_send![obj, setFoo:4u32]; + let _: () = msg_send![obj, setFoo: 4u32]; msg_send![obj, foo] }; assert!(result == 4); @@ -421,7 +421,7 @@ mod tests { let obj = test_utils::custom_subclass_object(); let superclass = test_utils::custom_class(); unsafe { - let _: () = msg_send![obj, setFoo:4u32]; + let _: () = msg_send![obj, setFoo: 4u32]; let foo: u32 = msg_send![super(obj, superclass), foo]; assert!(foo == 4); diff --git a/objc2/src/runtime.rs b/objc2/src/runtime.rs index 374663771..428a2ab67 100644 --- a/objc2/src/runtime.rs +++ b/objc2/src/runtime.rs @@ -533,7 +533,7 @@ mod tests { #[test] fn test_protocol_method() { let class = test_utils::custom_class(); - let result: i32 = unsafe { msg_send![class, addNumber:1 toNumber:2] }; + let result: i32 = unsafe { msg_send![class, addNumber: 1, toNumber: 2] }; assert_eq!(result, 3); } diff --git a/objc2_foundation/examples/custom_class.rs b/objc2_foundation/examples/custom_class.rs index 907cef8a1..e1f3916b1 100644 --- a/objc2_foundation/examples/custom_class.rs +++ b/objc2_foundation/examples/custom_class.rs @@ -82,7 +82,7 @@ fn main() { }); unsafe { - let _: () = msg_send![obj, setNumber:12u32]; + let _: () = msg_send![obj, setNumber: 12u32]; } println!("Number: {}", obj.number()); } diff --git a/objc2_foundation/src/array.rs b/objc2_foundation/src/array.rs index 94c15bc21..b78b13add 100644 --- a/objc2_foundation/src/array.rs +++ b/objc2_foundation/src/array.rs @@ -77,8 +77,11 @@ where { let cls = A::class(); let obj: *mut A = msg_send![cls, alloc]; - let obj: *mut A = msg_send![obj, initWithObjects:refs.as_ptr() - count:refs.len()]; + let obj: *mut A = msg_send![ + obj, + initWithObjects: refs.as_ptr(), + count: refs.len(), + ]; Id::new(NonNull::new_unchecked(obj)) } @@ -135,7 +138,7 @@ pub trait INSArray: INSObject { let range = NSRange::from_range(range); let mut vec = Vec::with_capacity(range.length); unsafe { - let _: () = msg_send![self, getObjects:vec.as_ptr() range:range]; + let _: () = msg_send![self, getObjects: vec.as_ptr(), range: range]; vec.set_len(range.length); } vec @@ -254,13 +257,13 @@ pub type NSSharedArray = NSArray; pub trait INSMutableArray: INSArray { fn add_object(&mut self, obj: Id) { unsafe { - let _: () = msg_send![self, addObject:&*obj]; + let _: () = msg_send![self, addObject: &*obj]; } } fn insert_object_at(&mut self, index: usize, obj: Id) { unsafe { - let _: () = msg_send![self, insertObject:&*obj atIndex:index]; + let _: () = msg_send![self, insertObject: &*obj, atIndex: index]; } } @@ -274,8 +277,11 @@ pub trait INSMutableArray: INSArray { Id::retain(obj.into()) }; unsafe { - let _: () = msg_send![self, replaceObjectAtIndex:index - withObject:&*obj]; + let _: () = msg_send![ + self, + replaceObjectAtIndex: index, + withObject: &*obj, + ]; } old_obj } @@ -333,7 +339,7 @@ pub trait INSMutableArray: INSArray { let context = &mut closure as *mut F as *mut c_void; unsafe { - let _: () = msg_send![self, sortUsingFunction:f context:context]; + let _: () = msg_send![self, sortUsingFunction: f, context: context]; } // Keep the closure alive until the function has run. drop(closure); diff --git a/objc2_foundation/src/data.rs b/objc2_foundation/src/data.rs index 422d69f8e..33cb925e6 100644 --- a/objc2_foundation/src/data.rs +++ b/objc2_foundation/src/data.rs @@ -35,8 +35,11 @@ pub trait INSData: INSObject { let bytes_ptr = bytes.as_ptr() as *const c_void; unsafe { let obj: *mut Self = msg_send![cls, alloc]; - let obj: *mut Self = msg_send![obj, initWithBytes:bytes_ptr - length:bytes.len()]; + let obj: *mut Self = msg_send![ + obj, + initWithBytes: bytes_ptr, + length: bytes.len(), + ]; Id::new(NonNull::new_unchecked(obj)) } } @@ -56,9 +59,12 @@ pub trait INSData: INSObject { let cls = Self::class(); unsafe { let obj: *mut Self = msg_send![cls, alloc]; - let obj: *mut Self = msg_send![obj, initWithBytesNoCopy:bytes_ptr - length:bytes.len() - deallocator:dealloc]; + let obj: *mut Self = msg_send![ + obj, + initWithBytesNoCopy: bytes_ptr, + length: bytes.len(), + deallocator: dealloc, + ]; core::mem::forget(bytes); Id::new(NonNull::new_unchecked(obj)) } @@ -98,8 +104,11 @@ pub trait INSMutableData: INSData { fn append(&mut self, bytes: &[u8]) { let bytes_ptr = bytes.as_ptr() as *const c_void; unsafe { - let _: () = msg_send![self, appendBytes:bytes_ptr - length:bytes.len()]; + let _: () = msg_send![ + self, + appendBytes: bytes_ptr, + length:bytes.len(), + ]; } } @@ -107,9 +116,12 @@ pub trait INSMutableData: INSData { let range = NSRange::from_range(range); let bytes_ptr = bytes.as_ptr() as *const c_void; unsafe { - let _: () = msg_send![self, replaceBytesInRange:range - withBytes:bytes_ptr - length:bytes.len()]; + let _: () = msg_send![ + self, + replaceBytesInRange:range, + withBytes:bytes_ptr, + length:bytes.len(), + ]; } } diff --git a/objc2_foundation/src/dictionary.rs b/objc2_foundation/src/dictionary.rs index 180f2b27e..5151494a1 100644 --- a/objc2_foundation/src/dictionary.rs +++ b/objc2_foundation/src/dictionary.rs @@ -18,9 +18,12 @@ where let cls = D::class(); let count = min(keys.len(), vals.len()); let obj: *mut D = msg_send![cls, alloc]; - let obj: *mut D = msg_send![obj, initWithObjects:vals.as_ptr() - forKeys:keys.as_ptr() - count:count]; + let obj: *mut D = msg_send![ + obj, + initWithObjects: vals.as_ptr(), + forKeys: keys.as_ptr(), + count: count, + ]; Id::new(NonNull::new_unchecked(obj)) } @@ -48,8 +51,11 @@ pub trait INSDictionary: INSObject { let len = self.count(); let mut keys = Vec::with_capacity(len); unsafe { - let _: () = msg_send![self, getObjects:ptr::null_mut::<&Self::Value>() - andKeys:keys.as_mut_ptr()]; + let _: () = msg_send![ + self, + getObjects: ptr::null_mut::<&Self::Value>(), + andKeys: keys.as_mut_ptr(), + ]; keys.set_len(len); } keys @@ -59,8 +65,11 @@ pub trait INSDictionary: INSObject { let len = self.count(); let mut vals = Vec::with_capacity(len); unsafe { - let _: () = msg_send![self, getObjects:vals.as_mut_ptr() - andKeys:ptr::null_mut::<&Self::Key>()]; + let _: () = msg_send![ + self, + getObjects: vals.as_mut_ptr(), + andKeys: ptr::null_mut::<&Self::Key>(), + ]; vals.set_len(len); } vals @@ -71,8 +80,11 @@ pub trait INSDictionary: INSObject { let mut keys = Vec::with_capacity(len); let mut objs = Vec::with_capacity(len); unsafe { - let _: () = msg_send![self, getObjects:objs.as_mut_ptr() - andKeys:keys.as_mut_ptr()]; + let _: () = msg_send![ + self, + getObjects: objs.as_mut_ptr(), + andKeys: keys.as_mut_ptr(), + ]; keys.set_len(len); objs.set_len(len); } @@ -100,7 +112,10 @@ pub trait INSDictionary: INSObject { } } - fn from_keys_and_objects(keys: &[&T], vals: Vec>) -> Id + fn from_keys_and_objects( + keys: &[&T], + vals: Vec>, + ) -> Id where T: INSCopying, { @@ -166,7 +181,7 @@ where #[cfg(test)] mod tests { use alloc::vec; - use objc2::rc::{Owned, Id}; + use objc2::rc::{Id, Owned}; use super::{INSDictionary, NSDictionary}; use crate::{INSArray, INSObject, INSString, NSObject, NSString}; diff --git a/objc2_foundation/src/enumerator.rs b/objc2_foundation/src/enumerator.rs index 8bd3fe9c9..b1d1fedfe 100644 --- a/objc2_foundation/src/enumerator.rs +++ b/objc2_foundation/src/enumerator.rs @@ -95,9 +95,12 @@ fn enumerate<'a, 'b: 'a, C: INSFastEnumeration>( let count: usize = unsafe { // Reborrow state so that we don't move it let state = &mut *state; - msg_send![object, countByEnumeratingWithState:state - objects:buf.as_mut_ptr() - count:buf.len()] + msg_send![ + object, + countByEnumeratingWithState: state, + objects: buf.as_mut_ptr(), + count: buf.len(), + ] }; if count > 0 { diff --git a/objc2_foundation/src/string.rs b/objc2_foundation/src/string.rs index 5e98a8b9d..ba7c3534a 100644 --- a/objc2_foundation/src/string.rs +++ b/objc2_foundation/src/string.rs @@ -63,9 +63,12 @@ pub trait INSString: INSObject { let bytes = string.as_ptr() as *const c_void; unsafe { let obj: *mut Self = msg_send![cls, alloc]; - let obj: *mut Self = msg_send![obj, initWithBytes:bytes - length:string.len() - encoding:UTF8_ENCODING]; + let obj: *mut Self = msg_send![ + obj, + initWithBytes: bytes, + length: string.len(), + encoding: UTF8_ENCODING, + ]; Id::new(NonNull::new_unchecked(obj)) } } diff --git a/objc2_foundation/src/value.rs b/objc2_foundation/src/value.rs index 9f844aa7e..339e0065d 100644 --- a/objc2_foundation/src/value.rs +++ b/objc2_foundation/src/value.rs @@ -43,8 +43,11 @@ pub trait INSValue: INSObject { let encoding = CString::new(Self::Value::ENCODING.to_string()).unwrap(); unsafe { let obj: *mut Self = msg_send![cls, alloc]; - let obj: *mut Self = msg_send![obj, initWithBytes:bytes - objCType:encoding.as_ptr()]; + let obj: *mut Self = msg_send![ + obj, + initWithBytes: bytes, + objCType: encoding.as_ptr(), + ]; Id::new(NonNull::new_unchecked(obj)) } }