From 399600d44326dc86a85f34c587c6793a4ceac4d5 Mon Sep 17 00:00:00 2001 From: Esteban Borai Date: Thu, 25 Aug 2022 22:13:36 -0400 Subject: [PATCH] fix: `'static` lifetime elision for examples Takes advantage of lifetime elision on some examples where the rule applies. Refer: https://doc.rust-lang.org/reference/lifetime-elision.html#static-lifetime-elision --- examples/animation.rs | 25 ++--- examples/autolayout.rs | 53 +++++----- examples/browser/main.rs | 94 ++++++++++-------- examples/browser/toolbar.rs | 12 +-- examples/calculator/button_row.rs | 8 +- examples/calculator/calculator.rs | 6 +- examples/calculator/content_view.rs | 14 +-- examples/calculator/main.rs | 15 +-- examples/custom_image_drawing.rs | 29 +++--- examples/defaults.rs | 2 +- examples/frame_layout.rs | 55 ++++++----- examples/ios-beta/main.rs | 6 +- examples/text_input.rs | 76 ++++++++------- examples/todos_list/add/mod.rs | 2 +- examples/todos_list/add/view.rs | 6 +- examples/todos_list/app.rs | 2 +- examples/todos_list/menu.rs | 96 +++++++++++-------- examples/todos_list/preferences/advanced.rs | 4 +- examples/todos_list/preferences/general.rs | 6 +- examples/todos_list/preferences/mod.rs | 6 +- .../preferences/toggle_option_view.rs | 8 +- examples/todos_list/preferences/toolbar.rs | 4 +- examples/todos_list/storage/defaults.rs | 2 +- examples/todos_list/storage/mod.rs | 2 +- examples/todos_list/storage/todos.rs | 10 +- examples/todos_list/todos/content_view.rs | 6 +- examples/todos_list/todos/list/mod.rs | 12 +-- examples/todos_list/todos/list/row.rs | 6 +- examples/todos_list/todos/mod.rs | 4 +- examples/todos_list/windows.rs | 10 +- examples/webview_custom_protocol.rs | 17 ++-- examples/window.rs | 38 ++++---- examples/window_controller.rs | 47 +++++---- examples/window_delegate.rs | 47 +++++---- src/appkit/animation.rs | 4 +- src/appkit/app/delegate.rs | 84 ++++++++-------- src/appkit/app/enums.rs | 14 +-- src/appkit/app/mod.rs | 8 +- src/appkit/cursor.rs | 4 +- src/appkit/enums.rs | 6 +- src/appkit/event/mod.rs | 12 +-- src/appkit/menu/item.rs | 16 ++-- src/appkit/menu/menu.rs | 59 +++++++----- src/appkit/printing/enums.rs | 4 +- src/appkit/printing/settings.rs | 4 +- src/appkit/toolbar/class.rs | 8 +- src/appkit/toolbar/enums.rs | 12 +-- src/appkit/toolbar/item.rs | 6 +- src/appkit/toolbar/mod.rs | 10 +- src/appkit/window/class.rs | 48 +++++----- src/appkit/window/config.rs | 6 +- src/appkit/window/controller/mod.rs | 4 +- src/appkit/window/enums.rs | 14 +-- src/appkit/window/mod.rs | 14 +-- src/button/enums.rs | 6 +- src/button/mod.rs | 8 +- src/cloudkit/share.rs | 4 +- src/color/appkit_dynamic_color.rs | 34 +++---- src/color/mod.rs | 22 ++--- src/control/mod.rs | 6 +- src/defaults/mod.rs | 2 +- src/defaults/value.rs | 30 +++--- src/dragdrop.rs | 10 +- src/error.rs | 4 +- src/events.rs | 8 +- src/filesystem/enums.rs | 12 +-- src/filesystem/save.rs | 4 +- src/filesystem/select.rs | 12 +-- src/foundation/autoreleasepool.rs | 2 +- src/foundation/class.rs | 4 +- src/foundation/mod.rs | 2 +- src/foundation/string.rs | 10 +- src/foundation/urls/bookmark_options.rs | 10 +- src/foundation/urls/mod.rs | 14 +-- src/foundation/urls/resource_keys.rs | 6 +- src/geometry.rs | 8 +- src/image/icons.rs | 10 +- src/image/image.rs | 22 ++--- src/image/mod.rs | 4 +- src/input/appkit.rs | 12 +-- src/input/mod.rs | 10 +- src/invoker.rs | 4 +- src/keys.rs | 2 +- src/layer/mod.rs | 6 +- src/layout/attributes.rs | 18 ++-- src/layout/constraint.rs | 6 +- src/layout/dimension.rs | 6 +- src/layout/horizontal.rs | 6 +- src/layout/safe_guide.rs | 6 +- src/layout/vertical.rs | 6 +- src/listview/actions.rs | 6 +- src/listview/appkit.rs | 42 ++++---- src/listview/enums.rs | 8 +- src/listview/mod.rs | 12 +-- src/listview/row/appkit.rs | 24 ++--- src/listview/row/mod.rs | 14 +-- src/notification_center/name.rs | 4 +- src/pasteboard/mod.rs | 2 +- src/pasteboard/types.rs | 8 +- src/progress/enums.rs | 4 +- src/progress/mod.rs | 4 +- src/quicklook/config.rs | 12 +-- src/quicklook/mod.rs | 2 +- src/scrollview/appkit.rs | 24 ++--- src/scrollview/mod.rs | 10 +- src/select/mod.rs | 4 +- src/switch.rs | 4 +- src/text/enums.rs | 8 +- src/text/label/mod.rs | 10 +- src/uikit/app/delegate.rs | 4 +- src/uikit/app/mod.rs | 6 +- src/uikit/scene/delegate.rs | 6 +- src/uikit/scene/enums.rs | 8 +- src/user_notifications/enums.rs | 6 +- src/utils/cell_factory.rs | 8 +- src/utils/mod.rs | 6 +- src/utils/os.rs | 2 +- src/utils/properties.rs | 2 +- src/view/appkit.rs | 24 ++--- src/view/controller/mod.rs | 4 +- src/view/controller/uikit.rs | 4 +- src/view/mod.rs | 8 +- src/view/splitviewcontroller/mod.rs | 16 ++-- src/webview/actions.rs | 16 ++-- src/webview/class.rs | 22 ++--- src/webview/config.rs | 4 +- src/webview/enums.rs | 18 ++-- src/webview/mimetype.rs | 8 +- src/webview/mod.rs | 8 +- 129 files changed, 942 insertions(+), 843 deletions(-) diff --git a/examples/animation.rs b/examples/animation.rs index 8d9de6c..c5d2bc5 100644 --- a/examples/animation.rs +++ b/examples/animation.rs @@ -15,7 +15,7 @@ use cacao::appkit::{AnimationContext, App, AppDelegate}; use cacao::appkit::{Event, EventMask, EventMonitor}; struct BasicApp { - window: Window + window: Window, } impl AppDelegate for BasicApp { @@ -54,22 +54,22 @@ const ANIMATIONS: [[[f64; 5]; 4]; 3] = [ [44., 16., 100., 100., 1.], [128., 84., 144., 124., 1.], [32., 32., 44., 44., 0.7], - [328., 157., 200., 200., 0.7] + [328., 157., 200., 200., 0.7], ], // Red [ [44., 132., 100., 100., 1.], [40., 47., 80., 64., 0.7], [84., 220., 600., 109., 1.0], - [48., 600., 340., 44., 0.7] + [48., 600., 340., 44., 0.7], ], // Green [ [44., 248., 100., 100., 1.], [420., 232., 420., 244., 0.7], [310., 440., 150., 238., 0.7], - [32., 32., 44., 44., 1.] - ] + [32., 32., 44., 44., 1.], + ], ]; /// A helper method for generating frame constraints that we want to be animating. @@ -84,7 +84,7 @@ fn apply_styles(view: &View, parent: &View, background_color: Color, animation_t view.top.constraint_equal_to(&parent.top).offset(animation[0]), view.left.constraint_equal_to(&parent.left).offset(animation[1]), view.width.constraint_equal_to_constant(animation[2]), - view.height.constraint_equal_to_constant(animation[3]) + view.height.constraint_equal_to_constant(animation[3]), ] } @@ -94,7 +94,7 @@ struct AppWindow { blue: View, red: View, green: View, - key_monitor: Option + key_monitor: Option, } impl WindowDelegate for AppWindow { @@ -139,7 +139,7 @@ impl WindowDelegate for AppWindow { "a" => 1, "s" => 2, "d" => 3, - _ => 4 + _ => 4, }; if animation_index == 4 { @@ -170,8 +170,11 @@ impl WindowDelegate for AppWindow { } fn main() { - App::new("com.test.window", BasicApp { - window: Window::with(WindowConfig::default(), AppWindow::default()) - }) + App::new( + "com.test.window", + BasicApp { + window: Window::with(WindowConfig::default(), AppWindow::default()), + }, + ) .run(); } diff --git a/examples/autolayout.rs b/examples/autolayout.rs index 6bcdecd..0fdb031 100644 --- a/examples/autolayout.rs +++ b/examples/autolayout.rs @@ -10,29 +10,35 @@ use cacao::appkit::window::{Window, WindowConfig, WindowDelegate}; use cacao::appkit::{App, AppDelegate}; struct BasicApp { - window: Window + window: Window, } impl AppDelegate for BasicApp { fn did_finish_launching(&self) { App::set_menu(vec![ - Menu::new("", vec![ - MenuItem::Services, - MenuItem::Separator, - MenuItem::Hide, - MenuItem::HideOthers, - MenuItem::ShowAll, - MenuItem::Separator, - MenuItem::Quit, - ]), + Menu::new( + "", + vec![ + MenuItem::Services, + MenuItem::Separator, + MenuItem::Hide, + MenuItem::HideOthers, + MenuItem::ShowAll, + MenuItem::Separator, + MenuItem::Quit, + ], + ), Menu::new("File", vec![MenuItem::CloseWindow]), Menu::new("View", vec![MenuItem::EnterFullScreen]), - Menu::new("Window", vec![ - MenuItem::Minimize, - MenuItem::Zoom, - MenuItem::Separator, - MenuItem::new("Bring All to Front"), - ]), + Menu::new( + "Window", + vec![ + MenuItem::Minimize, + MenuItem::Zoom, + MenuItem::Separator, + MenuItem::new("Bring All to Front"), + ], + ), ]); App::activate(); @@ -50,7 +56,7 @@ struct AppWindow { content: View, blue: View, red: View, - green: View + green: View, } impl WindowDelegate for AppWindow { @@ -62,7 +68,7 @@ impl WindowDelegate for AppWindow { let dynamic = Color::dynamic(|style| match (style.theme, style.contrast) { (Theme::Dark, _) => Color::SystemGreen, - _ => Color::SystemRed + _ => Color::SystemRed, }); self.blue.set_background_color(Color::SystemBlue); @@ -89,14 +95,17 @@ impl WindowDelegate for AppWindow { self.green.leading.constraint_equal_to(&self.red.trailing).offset(16.), self.green.trailing.constraint_equal_to(&self.content.trailing).offset(-16.), self.green.bottom.constraint_equal_to(&self.content.bottom).offset(-16.), - self.green.width.constraint_equal_to_constant(100.) + self.green.width.constraint_equal_to_constant(100.), ]); } } fn main() { - App::new("com.test.window", BasicApp { - window: Window::with(WindowConfig::default(), AppWindow::default()) - }) + App::new( + "com.test.window", + BasicApp { + window: Window::with(WindowConfig::default(), AppWindow::default()), + }, + ) .run(); } diff --git a/examples/browser/main.rs b/examples/browser/main.rs index e6433fc..4455317 100644 --- a/examples/browser/main.rs +++ b/examples/browser/main.rs @@ -16,7 +16,7 @@ use toolbar::BrowserToolbar; pub enum Action { Back, Forwards, - Load(String) + Load(String), } impl Action { @@ -26,39 +26,48 @@ impl Action { } struct BasicApp { - window: Window + window: Window, } impl AppDelegate for BasicApp { fn did_finish_launching(&self) { App::set_menu(vec![ - Menu::new("", vec![ - MenuItem::Services, - MenuItem::Separator, - MenuItem::Hide, - MenuItem::HideOthers, - MenuItem::ShowAll, - MenuItem::Separator, - MenuItem::Quit, - ]), + Menu::new( + "", + vec![ + MenuItem::Services, + MenuItem::Separator, + MenuItem::Hide, + MenuItem::HideOthers, + MenuItem::ShowAll, + MenuItem::Separator, + MenuItem::Quit, + ], + ), Menu::new("File", vec![MenuItem::CloseWindow]), - Menu::new("Edit", vec![ - MenuItem::Undo, - MenuItem::Redo, - MenuItem::Separator, - MenuItem::Cut, - MenuItem::Copy, - MenuItem::Paste, - MenuItem::Separator, - MenuItem::SelectAll, - ]), + Menu::new( + "Edit", + vec![ + MenuItem::Undo, + MenuItem::Redo, + MenuItem::Separator, + MenuItem::Cut, + MenuItem::Copy, + MenuItem::Paste, + MenuItem::Separator, + MenuItem::SelectAll, + ], + ), Menu::new("View", vec![MenuItem::EnterFullScreen]), - Menu::new("Window", vec![ - MenuItem::Minimize, - MenuItem::Zoom, - MenuItem::Separator, - MenuItem::new("Bring All to Front"), - ]), + Menu::new( + "Window", + vec![ + MenuItem::Minimize, + MenuItem::Zoom, + MenuItem::Separator, + MenuItem::new("Bring All to Front"), + ], + ), Menu::new("Help", vec![]), ]); @@ -83,7 +92,7 @@ impl Dispatcher for BasicApp { }, Action::Load(url) => { window.load_url(&url); - } + }, } } } @@ -95,14 +104,14 @@ impl WebViewDelegate for WebViewInstance {} struct AppWindow { toolbar: Toolbar, - content: WebView + content: WebView, } impl AppWindow { pub fn new() -> Self { AppWindow { toolbar: Toolbar::new("com.example.BrowserToolbar", BrowserToolbar::new()), - content: WebView::with(WebViewConfig::default(), WebViewInstance::default()) + content: WebView::with(WebViewConfig::default(), WebViewInstance::default()), } } @@ -128,18 +137,21 @@ impl WindowDelegate for AppWindow { } fn main() { - App::new("com.test.window", BasicApp { - window: Window::with( - { - let mut config = WindowConfig::default(); + App::new( + "com.test.window", + BasicApp { + window: Window::with( + { + let mut config = WindowConfig::default(); - // This flag is necessary for Big Sur to use the correct toolbar style. - config.toolbar_style = WindowToolbarStyle::Expanded; + // This flag is necessary for Big Sur to use the correct toolbar style. + config.toolbar_style = WindowToolbarStyle::Expanded; - config - }, - AppWindow::new() - ) - }) + config + }, + AppWindow::new(), + ), + }, + ) .run(); } diff --git a/examples/browser/toolbar.rs b/examples/browser/toolbar.rs index ecdbb6c..e5e8b49 100644 --- a/examples/browser/toolbar.rs +++ b/examples/browser/toolbar.rs @@ -7,9 +7,9 @@ use cacao::appkit::toolbar::{ItemIdentifier, Toolbar, ToolbarDelegate, ToolbarDi use super::Action; -const BACK_BUTTON: &'static str = "BackButton"; -const FWDS_BUTTON: &'static str = "FwdsButton"; -const URL_BAR: &'static str = "URLBar"; +const BACK_BUTTON: &str = "BackButton"; +const FWDS_BUTTON: &str = "FwdsButton"; +const URL_BAR: &str = "URLBar"; #[derive(Debug)] pub struct URLBar; @@ -27,7 +27,7 @@ pub struct BrowserToolbar { back_item: ToolbarItem, forwards_item: ToolbarItem, url_bar: TextField, - url_bar_item: ToolbarItem + url_bar_item: ToolbarItem, } impl BrowserToolbar { @@ -59,7 +59,7 @@ impl BrowserToolbar { back_item, forwards_item, url_bar, - url_bar_item + url_bar_item, } } @@ -100,7 +100,7 @@ impl ToolbarDelegate for BrowserToolbar { URL_BAR => &self.url_bar_item, _ => { std::unreachable!(); - } + }, } } } diff --git a/examples/calculator/button_row.rs b/examples/calculator/button_row.rs index 053c9bb..3842c1c 100644 --- a/examples/calculator/button_row.rs +++ b/examples/calculator/button_row.rs @@ -8,7 +8,7 @@ use crate::content_view::{button, BUTTON_HEIGHT, BUTTON_WIDTH}; pub struct ButtonRow { pub view: View, - pub buttons: Vec