From e5ca2369940192da58238a583060161cbda22b21 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 16 Jun 2017 10:03:20 -0700 Subject: [PATCH] rustfmt. --- examples/simple.rs | 44 +++++++++++++++++++++++++------------------- src/lib.rs | 8 ++++---- src/osx/mod.rs | 37 ++++++++++++++++++++----------------- src/osx/objc_ext.rs | 4 ++-- 4 files changed, 51 insertions(+), 42 deletions(-) diff --git a/examples/simple.rs b/examples/simple.rs index e3a1c00..b3f21dc 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -15,28 +15,34 @@ fn main() { let hm = Arc::new(RwLock::new(hm)); let phm = hm.clone(); - fly.add_item("Prefs", - Box::new(move || { - let mut hm = phm.write().unwrap(); - let size = hm.len(); - let k = format!("Prefs{}", size); - hm.insert(k, "Bar".to_owned()); - - println!("prefs selected, new hm {:?}", *hm); - })); + fly.add_item( + "Prefs", + Box::new(move || { + let mut hm = phm.write().unwrap(); + let size = hm.len(); + let k = format!("Prefs{}", size); + hm.insert(k, "Bar".to_owned()); + + println!("prefs selected, new hm {:?}", *hm); + }), + ); let fhm = hm.clone(); - fly.add_item("Summon Herb", - Box::new(move || { - let mut hm = fhm.write().unwrap(); - let size = hm.len(); - let k = format!("Herb{}", size); - hm.insert(k, "Bar".to_owned()); - - println!("Herb thinks you are a jerk and refuses to appear. By the way, \ + fly.add_item( + "Summon Herb", + Box::new(move || { + let mut hm = fhm.write().unwrap(); + let size = hm.len(); + let k = format!("Herb{}", size); + hm.insert(k, "Bar".to_owned()); + + println!( + "Herb thinks you are a jerk and refuses to appear. By the way, \ the hash map is: {:?}", - *hm); - })); + *hm + ); + }), + ); fly.add_quit_item("Quit"); diff --git a/src/lib.rs b/src/lib.rs index f414fdd..e61572c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ -#[cfg(target_os="macos")] +#[cfg(target_os = "macos")] mod osx; -#[cfg(target_os="macos")] +#[cfg(target_os = "macos")] #[macro_use] extern crate objc; @@ -15,8 +15,8 @@ pub trait Barfly { #[cfg(target_os = "macos")] pub type PlatformFly = osx::OsxBarfly; -pub fn new(name:&str) -> PlatformFly { - PlatformFly::new(name) +pub fn new(name: &str) -> PlatformFly { + PlatformFly::new(name) } #[test] diff --git a/src/osx/mod.rs b/src/osx/mod.rs index e02951d..bab30f3 100644 --- a/src/osx/mod.rs +++ b/src/osx/mod.rs @@ -8,8 +8,9 @@ pub use objc::Message; extern crate cocoa; pub use self::cocoa::base::{selector, nil, YES /* id, class, BOOL */}; -pub use self::cocoa::appkit::{NSApp, NSApplication, NSWindow, NSMenu, NSMenuItem, NSRunningApplication, - NSApplicationActivateIgnoringOtherApps, NSStatusBar}; +pub use self::cocoa::appkit::{NSApp, NSApplication, NSWindow, NSMenu, NSMenuItem, + NSRunningApplication, NSApplicationActivateIgnoringOtherApps, + NSStatusBar}; extern crate libc; pub use self::libc::c_void; @@ -20,7 +21,7 @@ extern crate objc_id; pub use self::objc_id::Id; mod objc_ext; -use self::objc_ext::{NSStatusItem}; +use self::objc_ext::NSStatusItem; extern crate objc_foundation; pub use self::cocoa::foundation::{NSAutoreleasePool, NSString}; @@ -39,7 +40,8 @@ impl Barfly for OsxBarfly { unsafe { OsxBarfly { name: name.to_owned(), - pool: NSAutoreleasePool::new(nil), /* TODO: not sure about the consequences of creating this here */ + /* TODO: not sure about the consequences of creating this here */ + pool: NSAutoreleasePool::new(nil), menu: NSMenu::new(nil).autorelease(), } } @@ -56,11 +58,9 @@ impl Barfly for OsxBarfly { let itemtitle = NSString::init_str(astring, menuItem); let action = sel!(call); let aitem = NSMenuItem::alloc(nil); - let item = NSMenuItem::initWithTitle_action_keyEquivalent_(aitem, - itemtitle, - action, - no_key); - let _: () = msg_send![item, setTarget:cb_obj]; + let item = + NSMenuItem::initWithTitle_action_keyEquivalent_(aitem, itemtitle, action, no_key); + let _: () = msg_send![item, setTarget: cb_obj]; NSMenu::addItem_(self.menu, item); } @@ -70,11 +70,13 @@ impl Barfly for OsxBarfly { fn add_quit_item(&mut self, label: &str) { unsafe { let no_key = NSString::alloc(nil).init_str(""); - let pref_item = NSString::alloc(nil) - .init_str(label); + let pref_item = NSString::alloc(nil).init_str(label); let pref_action = selector("terminate:"); - let menuitem = NSMenuItem::alloc(nil) - .initWithTitle_action_keyEquivalent_(pref_item, pref_action, no_key); + let menuitem = NSMenuItem::alloc(nil).initWithTitle_action_keyEquivalent_( + pref_item, + pref_action, + no_key, + ); self.menu.addItem_(menuitem); } @@ -87,8 +89,7 @@ impl Barfly for OsxBarfly { let item = NSStatusBar::systemStatusBar(nil).statusItemWithLength_(-1.0); item.setHighlightMode_(YES); - let title = NSString::alloc(nil) - .init_str(&self.name); + let title = NSString::alloc(nil).init_str(&self.name); item.setTitle_(title); item.setMenu_(self.menu); @@ -169,8 +170,10 @@ impl INSObject for Callback { } unsafe { - decl.add_method(sel!(call), - barfly_callback_call as extern "C" fn(&Object, Sel)); + decl.add_method( + sel!(call), + barfly_callback_call as extern "C" fn(&Object, Sel), + ); } decl.register(); diff --git a/src/osx/objc_ext.rs b/src/osx/objc_ext.rs index e2f8a4b..846bd38 100644 --- a/src/osx/objc_ext.rs +++ b/src/osx/objc_ext.rs @@ -12,12 +12,12 @@ pub trait NSStatusItem { impl NSStatusItem for id { unsafe fn setHighlightMode_(self, mode: BOOL) { - msg_send![self, setHighlightMode:mode] + msg_send![self, setHighlightMode: mode] } unsafe fn statusBar(self) -> id { msg_send![self, statusBar] } unsafe fn setMenu_(self, menu: id) { - msg_send![self, setMenu:menu] + msg_send![self, setMenu: menu] } } -- 2.51.2