Skip to content

Commit 7cee916

Browse files
committed
Run "cargo fmt" (rustfmt) over core-foundation-rs
1 parent 7b3caa7 commit 7cee916

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+6064
-3580
lines changed

cocoa-foundation/src/foundation.rs

+490-220
Large diffs are not rendered by default.

cocoa-foundation/tests/foundation.rs

+27-22
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ extern crate cocoa_foundation;
66
#[cfg(test)]
77
mod foundation {
88
mod nsstring {
9-
use cocoa_foundation::foundation::NSString;
109
use cocoa_foundation::base::nil;
10+
use cocoa_foundation::foundation::NSString;
1111
use std::slice;
1212
use std::str;
1313

@@ -17,8 +17,8 @@ mod foundation {
1717
unsafe {
1818
let built = NSString::alloc(nil).init_str(expected);
1919
let bytes = built.UTF8String() as *const u8;
20-
let objc_string = str::from_utf8(slice::from_raw_parts(bytes, built.len()))
21-
.unwrap();
20+
let objc_string =
21+
str::from_utf8(slice::from_raw_parts(bytes, built.len())).unwrap();
2222
assert_eq!(objc_string.len(), expected.len());
2323
assert_eq!(objc_string, expected);
2424
}
@@ -30,8 +30,8 @@ mod foundation {
3030
unsafe {
3131
let built = NSString::alloc(nil).init_str(expected);
3232
let bytes = built.UTF8String() as *const u8;
33-
let objc_string = str::from_utf8(slice::from_raw_parts(bytes, built.len()))
34-
.unwrap();
33+
let objc_string =
34+
str::from_utf8(slice::from_raw_parts(bytes, built.len())).unwrap();
3535
assert_eq!(objc_string.len(), expected.len());
3636
assert_eq!(objc_string, expected);
3737
}
@@ -56,18 +56,18 @@ mod foundation {
5656
let built_to_append = NSString::alloc(nil).init_str(to_append);
5757
let append_string = built.stringByAppendingString_(built_to_append);
5858
let bytes = append_string.UTF8String() as *const u8;
59-
let objc_string = str::from_utf8(slice::from_raw_parts(bytes, append_string.len()))
60-
.unwrap();
59+
let objc_string =
60+
str::from_utf8(slice::from_raw_parts(bytes, append_string.len())).unwrap();
6161
assert_eq!(objc_string, expected);
6262
}
6363
}
6464
}
6565

6666
mod nsfastenumeration {
67-
use std::str;
68-
use std::slice;
69-
use cocoa_foundation::foundation::{NSString, NSFastEnumeration};
7067
use cocoa_foundation::base::{id, nil};
68+
use cocoa_foundation::foundation::{NSFastEnumeration, NSString};
69+
use std::slice;
70+
use std::str;
7171

7272
#[test]
7373
fn test_iter() {
@@ -76,7 +76,8 @@ mod foundation {
7676
let separator = NSString::alloc(nil).init_str(" ");
7777
let components: id = msg_send![string, componentsSeparatedByString: separator];
7878

79-
let combined = components.iter()
79+
let combined = components
80+
.iter()
8081
.map(|s| {
8182
let bytes = s.UTF8String() as *const u8;
8283
str::from_utf8(slice::from_raw_parts(bytes, s.len())).unwrap()
@@ -108,9 +109,10 @@ mod foundation {
108109

109110
mod nsdictionary {
110111
use block::ConcreteBlock;
111-
use cocoa_foundation::foundation::{NSArray, NSComparisonResult, NSDictionary, NSFastEnumeration,
112-
NSString};
113112
use cocoa_foundation::base::{id, nil};
113+
use cocoa_foundation::foundation::{
114+
NSArray, NSComparisonResult, NSDictionary, NSFastEnumeration, NSString,
115+
};
114116

115117
#[test]
116118
fn test_get() {
@@ -132,8 +134,8 @@ mod foundation {
132134
let keys = vec!["a", "b", "c", "d", "e", "f"];
133135
let objects = vec!["1", "2", "3", "4", "5", "6"];
134136
unsafe {
135-
use std::{slice, str};
136137
use std::cmp::{Ord, Ordering};
138+
use std::{slice, str};
137139

138140
let keys_raw_vec = keys.clone().into_iter().map(&mkstr).collect::<Vec<_>>();
139141
let objs_raw_vec = objects.clone().into_iter().map(&mkstr).collect::<Vec<_>>();
@@ -152,26 +154,29 @@ mod foundation {
152154
unsafe {
153155
let (bytes0, len0) = (s0.UTF8String() as *const u8, s0.len());
154156
let (bytes1, len1) = (s1.UTF8String() as *const u8, s1.len());
155-
let (s0, s1) = (str::from_utf8(slice::from_raw_parts(bytes0, len0)).unwrap(),
156-
str::from_utf8(slice::from_raw_parts(bytes1, len1)).unwrap());
157+
let (s0, s1) = (
158+
str::from_utf8(slice::from_raw_parts(bytes0, len0)).unwrap(),
159+
str::from_utf8(slice::from_raw_parts(bytes1, len1)).unwrap(),
160+
);
157161
let (c0, c1) = (s0.chars().next().unwrap(), s1.chars().next().unwrap());
158162
c0.cmp(&c1)
159163
}
160164
}
161165

162166
// First test cocoa sorting...
163-
let mut comparator = ConcreteBlock::new(|s0: id, s1: id| {
164-
match compare_function(&s0, &s1) {
167+
let mut comparator =
168+
ConcreteBlock::new(|s0: id, s1: id| match compare_function(&s0, &s1) {
165169
Ordering::Less => NSComparisonResult::NSOrderedAscending,
166170
Ordering::Equal => NSComparisonResult::NSOrderedSame,
167171
Ordering::Greater => NSComparisonResult::NSOrderedDescending,
168-
}
169-
});
172+
});
170173

171174
let associated_iter = keys.iter().zip(objects.iter());
172-
for (k_id, (k, v)) in dict.keysSortedByValueUsingComparator_(&mut *comparator)
175+
for (k_id, (k, v)) in dict
176+
.keysSortedByValueUsingComparator_(&mut *comparator)
173177
.iter()
174-
.zip(associated_iter) {
178+
.zip(associated_iter)
179+
{
175180
assert!(k_id.isEqualToString(k));
176181
let v_id = dict.objectForKey_(k_id);
177182
assert!(v_id.isEqualToString(v));

cocoa/examples/color.rs

+45-28
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
extern crate cocoa;
22

3-
use cocoa::base::{selector, id, nil, NO};
4-
5-
use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo,
6-
NSString};
7-
use cocoa::appkit::{NSApp, NSColor, NSColorSpace, NSApplication, NSApplicationActivationPolicyRegular,
8-
NSMenu, NSMenuItem, NSWindowStyleMask, NSBackingStoreType, NSWindow,
9-
NSRunningApplication, NSApplicationActivateIgnoringOtherApps};
3+
use cocoa::base::{id, nil, selector, NO};
104

5+
use cocoa::appkit::{
6+
NSApp, NSApplication, NSApplicationActivateIgnoringOtherApps,
7+
NSApplicationActivationPolicyRegular, NSBackingStoreType, NSColor, NSColorSpace, NSMenu,
8+
NSMenuItem, NSRunningApplication, NSWindow, NSWindowStyleMask,
9+
};
10+
use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSProcessInfo, NSRect, NSSize, NSString};
1111

1212
fn main() {
1313
unsafe {
1414
// Create the app.
1515
let app = create_app();
16-
16+
1717
// Create some colors
1818
let clear = NSColor::clearColor(nil);
1919
let black = NSColor::colorWithRed_green_blue_alpha_(nil, 0.0, 0.0, 0.0, 1.0);
2020
let srgb_red = NSColor::colorWithSRGBRed_green_blue_alpha_(nil, 1.0, 0.0, 0.0, 1.0);
2121
let device_green = NSColor::colorWithDeviceRed_green_blue_alpha_(nil, 0.0, 1.0, 0.0, 1.0);
22-
let display_p3_blue = NSColor::colorWithDisplayP3Red_green_blue_alpha_(nil, 0.0, 0.0, 1.0, 1.0);
23-
let calibrated_cyan = NSColor::colorWithCalibratedRed_green_blue_alpha_(nil, 0.0, 1.0, 1.0, 1.0);
22+
let display_p3_blue =
23+
NSColor::colorWithDisplayP3Red_green_blue_alpha_(nil, 0.0, 0.0, 1.0, 1.0);
24+
let calibrated_cyan =
25+
NSColor::colorWithCalibratedRed_green_blue_alpha_(nil, 0.0, 1.0, 1.0, 1.0);
2426

2527
// Create windows with different color types.
2628
let _win_clear = create_window(NSString::alloc(nil).init_str("clear"), clear);
2729
let _win_black = create_window(NSString::alloc(nil).init_str("black"), black);
2830
let _win_srgb_red = create_window(NSString::alloc(nil).init_str("srgb_red"), srgb_red);
29-
let _win_device_green = create_window(NSString::alloc(nil).init_str("device_green"), device_green);
30-
let _win_display_p3_blue = create_window(NSString::alloc(nil).init_str("display_p3_blue"), display_p3_blue);
31-
let _win_calibrated_cyan = create_window(NSString::alloc(nil).init_str("calibrated_cyan"), calibrated_cyan);
31+
let _win_device_green =
32+
create_window(NSString::alloc(nil).init_str("device_green"), device_green);
33+
let _win_display_p3_blue = create_window(
34+
NSString::alloc(nil).init_str("display_p3_blue"),
35+
display_p3_blue,
36+
);
37+
let _win_calibrated_cyan = create_window(
38+
NSString::alloc(nil).init_str("calibrated_cyan"),
39+
calibrated_cyan,
40+
);
3241

3342
// Extract component values from a color.
3443
// NOTE: some components will raise an exception if the color is not
@@ -42,44 +51,52 @@ fn main() {
4251
println!("hueComponent: {:?}", my_color.hueComponent());
4352
println!("saturationComponent: {:?}", my_color.saturationComponent());
4453
println!("brightnessComponent: {:?}", my_color.brightnessComponent());
45-
54+
4655
// Changing color spaces.
47-
let my_color_cmyk_cs = my_color.colorUsingColorSpace_(NSColorSpace::deviceCMYKColorSpace(nil));
56+
let my_color_cmyk_cs =
57+
my_color.colorUsingColorSpace_(NSColorSpace::deviceCMYKColorSpace(nil));
4858
println!("blackComponent: {:?}", my_color_cmyk_cs.blackComponent());
4959
println!("cyanComponent: {:?}", my_color_cmyk_cs.cyanComponent());
50-
println!("magentaComponent: {:?}", my_color_cmyk_cs.magentaComponent());
60+
println!(
61+
"magentaComponent: {:?}",
62+
my_color_cmyk_cs.magentaComponent()
63+
);
5164
println!("yellowComponent: {:?}", my_color_cmyk_cs.yellowComponent());
5265

5366
// Getting NSColorSpace name.
5467
let cs = NSColorSpace::genericGamma22GrayColorSpace(nil);
5568
let cs_name = cs.localizedName();
5669
let cs_name_bytes = cs_name.UTF8String() as *const u8;
57-
let cs_name_string = std::str::from_utf8(std::slice::from_raw_parts(cs_name_bytes, cs_name.len())).unwrap();
70+
let cs_name_string =
71+
std::str::from_utf8(std::slice::from_raw_parts(cs_name_bytes, cs_name.len())).unwrap();
5872
println!("NSColorSpace: {:?}", cs_name_string);
5973

6074
// Creating an NSColorSpace from CGColorSpaceRef.
6175
let cg_cs = cs.CGColorSpace();
6276
let cs = NSColorSpace::alloc(nil).initWithCGColorSpace_(cg_cs);
6377
let cs_name = cs.localizedName();
6478
let cs_name_bytes = cs_name.UTF8String() as *const u8;
65-
let cs_name_string = std::str::from_utf8(std::slice::from_raw_parts(cs_name_bytes, cs_name.len())).unwrap();
79+
let cs_name_string =
80+
std::str::from_utf8(std::slice::from_raw_parts(cs_name_bytes, cs_name.len())).unwrap();
6681
println!("initWithCGColorSpace_: {:?}", cs_name_string);
6782

6883
app.run();
6984
}
7085
}
7186

7287
unsafe fn create_window(title: id, color: id) -> id {
73-
let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_(
74-
NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)),
75-
NSWindowStyleMask::NSTitledWindowMask |
76-
NSWindowStyleMask::NSClosableWindowMask |
77-
NSWindowStyleMask::NSResizableWindowMask |
78-
NSWindowStyleMask::NSMiniaturizableWindowMask |
79-
NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask,
80-
NSBackingStoreType::NSBackingStoreBuffered,
81-
NO
82-
).autorelease();
88+
let window = NSWindow::alloc(nil)
89+
.initWithContentRect_styleMask_backing_defer_(
90+
NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)),
91+
NSWindowStyleMask::NSTitledWindowMask
92+
| NSWindowStyleMask::NSClosableWindowMask
93+
| NSWindowStyleMask::NSResizableWindowMask
94+
| NSWindowStyleMask::NSMiniaturizableWindowMask
95+
| NSWindowStyleMask::NSUnifiedTitleAndToolbarWindowMask,
96+
NSBackingStoreType::NSBackingStoreBuffered,
97+
NO,
98+
)
99+
.autorelease();
83100

84101
window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.));
85102
window.setTitle_(title);

cocoa/examples/fullscreen.rs

+42-22
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ extern crate core_graphics;
44
#[macro_use]
55
extern crate objc;
66

7-
use cocoa::base::{selector, nil, NO, id};
8-
use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo,
9-
NSString, NSUInteger};
10-
use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow,
11-
NSBackingStoreBuffered, NSMenu, NSMenuItem, NSWindowStyleMask,
12-
NSRunningApplication, NSApplicationActivateIgnoringOtherApps,
13-
NSWindowCollectionBehavior, NSApplicationPresentationOptions};
7+
use cocoa::appkit::{
8+
NSApp, NSApplication, NSApplicationActivateIgnoringOtherApps,
9+
NSApplicationActivationPolicyRegular, NSApplicationPresentationOptions, NSBackingStoreBuffered,
10+
NSMenu, NSMenuItem, NSRunningApplication, NSWindow, NSWindowCollectionBehavior,
11+
NSWindowStyleMask,
12+
};
13+
use cocoa::base::{id, nil, selector, NO};
14+
use cocoa::foundation::{
15+
NSAutoreleasePool, NSPoint, NSProcessInfo, NSRect, NSSize, NSString, NSUInteger,
16+
};
1417

1518
use core_graphics::display::CGDisplay;
1619

17-
use objc::runtime::{Object, Sel};
1820
use objc::declare::ClassDecl;
21+
use objc::runtime::{Object, Sel};
1922

2023
fn main() {
2124
unsafe {
@@ -47,7 +50,12 @@ fn main() {
4750
let superclass = class!(NSObject);
4851
let mut decl = ClassDecl::new("MyWindowDelegate", superclass).unwrap();
4952

50-
extern fn will_use_fillscreen_presentation_options(_: &Object, _: Sel, _: id, _: NSUInteger) -> NSUInteger {
53+
extern "C" fn will_use_fillscreen_presentation_options(
54+
_: &Object,
55+
_: Sel,
56+
_: id,
57+
_: NSUInteger,
58+
) -> NSUInteger {
5159
// Set initial presentation options for fullscreen
5260
let options = NSApplicationPresentationOptions::NSApplicationPresentationFullScreen
5361
| NSApplicationPresentationOptions::NSApplicationPresentationHideDock
@@ -56,20 +64,28 @@ fn main() {
5664
options.bits()
5765
}
5866

59-
extern fn window_entering_fullscreen(_: &Object, _: Sel, _: id) {
67+
extern "C" fn window_entering_fullscreen(_: &Object, _: Sel, _: id) {
6068
// Reset HideDock and HideMenuBar settings during/after we entered fullscreen.
61-
let options = NSApplicationPresentationOptions::NSApplicationPresentationHideDock | NSApplicationPresentationOptions::NSApplicationPresentationHideMenuBar;
69+
let options = NSApplicationPresentationOptions::NSApplicationPresentationHideDock
70+
| NSApplicationPresentationOptions::NSApplicationPresentationHideMenuBar;
6271
unsafe {
6372
NSApp().setPresentationOptions_(options);
6473
}
6574
}
6675

67-
decl.add_method(sel!(window:willUseFullScreenPresentationOptions:),
68-
will_use_fillscreen_presentation_options as extern fn(&Object, Sel, id, NSUInteger) -> NSUInteger);
69-
decl.add_method(sel!(windowWillEnterFullScreen:),
70-
window_entering_fullscreen as extern fn(&Object, Sel, id));
71-
decl.add_method(sel!(windowDidEnterFullScreen:),
72-
window_entering_fullscreen as extern fn(&Object, Sel, id));
76+
decl.add_method(
77+
sel!(window:willUseFullScreenPresentationOptions:),
78+
will_use_fillscreen_presentation_options
79+
as extern "C" fn(&Object, Sel, id, NSUInteger) -> NSUInteger,
80+
);
81+
decl.add_method(
82+
sel!(windowWillEnterFullScreen:),
83+
window_entering_fullscreen as extern "C" fn(&Object, Sel, id),
84+
);
85+
decl.add_method(
86+
sel!(windowDidEnterFullScreen:),
87+
window_entering_fullscreen as extern "C" fn(&Object, Sel, id),
88+
);
7389

7490
let delegate_class = decl.register();
7591
let delegate_object = msg_send![delegate_class, new];
@@ -78,10 +94,12 @@ fn main() {
7894
let display = CGDisplay::main();
7995
let size = NSSize::new(display.pixels_wide() as _, display.pixels_high() as _);
8096
let window = NSWindow::alloc(nil)
81-
.initWithContentRect_styleMask_backing_defer_(NSRect::new(NSPoint::new(0., 0.), size),
82-
NSWindowStyleMask::NSTitledWindowMask,
83-
NSBackingStoreBuffered,
84-
NO)
97+
.initWithContentRect_styleMask_backing_defer_(
98+
NSRect::new(NSPoint::new(0., 0.), size),
99+
NSWindowStyleMask::NSTitledWindowMask,
100+
NSBackingStoreBuffered,
101+
NO,
102+
)
85103
.autorelease();
86104
window.setDelegate_(delegate_object);
87105
let title = NSString::alloc(nil).init_str("Fullscreen!");
@@ -90,7 +108,9 @@ fn main() {
90108

91109
let current_app = NSRunningApplication::currentApplication(nil);
92110
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
93-
window.setCollectionBehavior_(NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenPrimary);
111+
window.setCollectionBehavior_(
112+
NSWindowCollectionBehavior::NSWindowCollectionBehaviorFullScreenPrimary,
113+
);
94114
window.toggleFullScreen_(nil);
95115
app.run();
96116
}

cocoa/examples/hello_world.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
extern crate cocoa;
22

3-
use cocoa::base::{selector, nil, NO};
4-
use cocoa::foundation::{NSRect, NSPoint, NSSize, NSAutoreleasePool, NSProcessInfo,
5-
NSString};
6-
use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSWindow,
7-
NSBackingStoreBuffered, NSMenu, NSMenuItem, NSWindowStyleMask,
8-
NSRunningApplication, NSApplicationActivateIgnoringOtherApps};
3+
use cocoa::appkit::{
4+
NSApp, NSApplication, NSApplicationActivateIgnoringOtherApps,
5+
NSApplicationActivationPolicyRegular, NSBackingStoreBuffered, NSMenu, NSMenuItem,
6+
NSRunningApplication, NSWindow, NSWindowStyleMask,
7+
};
8+
use cocoa::base::{nil, selector, NO};
9+
use cocoa::foundation::{NSAutoreleasePool, NSPoint, NSProcessInfo, NSRect, NSSize, NSString};
910

1011
fn main() {
1112
unsafe {
@@ -35,11 +36,12 @@ fn main() {
3536

3637
// create Window
3738
let window = NSWindow::alloc(nil)
38-
.initWithContentRect_styleMask_backing_defer_(NSRect::new(NSPoint::new(0., 0.),
39-
NSSize::new(200., 200.)),
40-
NSWindowStyleMask::NSTitledWindowMask,
41-
NSBackingStoreBuffered,
42-
NO)
39+
.initWithContentRect_styleMask_backing_defer_(
40+
NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)),
41+
NSWindowStyleMask::NSTitledWindowMask,
42+
NSBackingStoreBuffered,
43+
NO,
44+
)
4345
.autorelease();
4446
window.cascadeTopLeftFromPoint_(NSPoint::new(20., 20.));
4547
window.center();

0 commit comments

Comments
 (0)