From e096dc97407bf0690e2f3544de85f308c7b93f19 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Thu, 28 Feb 2019 15:55:02 -0800 Subject: [PATCH] Run cargo fix --edition-idioms --- src/backend/blt.rs | 4 ++-- src/backend/curses/n.rs | 4 ++-- src/backend/curses/pan.rs | 4 ++-- src/backend/dummy.rs | 2 +- src/backend/termion.rs | 6 +++--- src/cursive.rs | 16 ++++++++-------- src/event.rs | 22 +++++++++++----------- src/lib.rs | 19 +++++++++---------- src/logger.rs | 4 ++-- src/printer.rs | 22 +++++++++++----------- src/theme/color.rs | 6 +++--- src/utf8.rs | 4 ++-- src/utils/markup/markdown.rs | 2 +- src/utils/span.rs | 11 ++++------- src/view/any.rs | 12 ++++++------ src/view/finder.rs | 6 +++--- src/view/into_boxed_view.rs | 8 ++++---- src/view/scroll.rs | 4 ++-- src/view/view.rs | 6 +++--- src/view/view_wrapper.rs | 12 ++++++------ src/views/button.rs | 2 +- src/views/canvas.rs | 36 ++++++++++++++++++------------------ src/views/checkbox.rs | 6 +++--- src/views/debug_view.rs | 2 +- src/views/dialog.rs | 16 ++++++++-------- src/views/dummy.rs | 2 +- src/views/edit_view.rs | 6 +++--- src/views/enableable_view.rs | 2 +- src/views/hideable_view.rs | 2 +- src/views/id_view.rs | 6 +++--- src/views/layer.rs | 2 +- src/views/linear_layout.rs | 18 +++++++++--------- src/views/list_view.rs | 14 +++++++------- src/views/menu_popup.rs | 2 +- src/views/menubar.rs | 2 +- src/views/on_event_view.rs | 2 +- src/views/padded_view.rs | 2 +- src/views/panel.rs | 4 ++-- src/views/progress_bar.rs | 4 ++-- src/views/radio.rs | 6 +++--- src/views/scroll_view.rs | 6 +++--- src/views/select_view.rs | 8 ++++---- src/views/shadow_view.rs | 2 +- src/views/slider_view.rs | 6 +++--- src/views/stack_view.rs | 24 ++++++++++++------------ src/views/text_area.rs | 2 +- src/views/text_view.rs | 2 +- src/views/tracked_view.rs | 2 +- src/views/view_box.rs | 14 +++++++------- 49 files changed, 186 insertions(+), 190 deletions(-) diff --git a/src/backend/blt.rs b/src/backend/blt.rs index 78bb320..ce1b06d 100644 --- a/src/backend/blt.rs +++ b/src/backend/blt.rs @@ -3,7 +3,7 @@ //! Requires the `blt-backend` feature. #![cfg(feature = "bear-lib-terminal")] -extern crate bear_lib_terminal; +use bear_lib_terminal; use std::collections::HashSet; @@ -31,7 +31,7 @@ pub struct Backend { impl Backend { /// Creates a new BearLibTerminal-based backend. - pub fn init() -> Box { + pub fn init() -> Box { terminal::open("Cursive", 80, 24); terminal::set(terminal::config::Window::empty().resizeable(true)); terminal::set(vec![ diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index be98fa5..c1608ce 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -1,5 +1,5 @@ //! Ncurses-specific backend. -extern crate ncurses; +use ncurses; use std::cell::{Cell, RefCell}; use std::collections::HashMap; @@ -56,7 +56,7 @@ fn write_to_tty(bytes: &[u8]) -> io::Result<()> { impl Backend { /// Creates a new ncurses-based backend. - pub fn init() -> Box { + pub fn init() -> Box { // Change the locale. // For some reasons it's mandatory to get some UTF-8 support. ncurses::setlocale(ncurses::LcCategory::all, ""); diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index 4bc01a1..9b2bfab 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -1,5 +1,5 @@ //! Pancuses-specific backend. -extern crate pancurses; +use pancurses; use std::cell::{Cell, RefCell}; use std::collections::HashMap; @@ -33,7 +33,7 @@ fn find_closest_pair(pair: ColorPair) -> (i16, i16) { impl Backend { /// Creates a new pancurses-based backend. - pub fn init() -> Box { + pub fn init() -> Box { ::std::env::set_var("ESCDELAY", "25"); let window = pancurses::initscr(); diff --git a/src/backend/dummy.rs b/src/backend/dummy.rs index e64dc97..da6bf95 100644 --- a/src/backend/dummy.rs +++ b/src/backend/dummy.rs @@ -12,7 +12,7 @@ pub struct Backend; impl Backend { /// Creates a new dummy backend. - pub fn init() -> Box + pub fn init() -> Box where Self: Sized, { diff --git a/src/backend/termion.rs b/src/backend/termion.rs index b4640e2..2a90fe1 100644 --- a/src/backend/termion.rs +++ b/src/backend/termion.rs @@ -3,7 +3,7 @@ //! Requires the `termion-backend` feature. #![cfg(feature = "termion")] -extern crate termion; +use termion; use self::termion::color as tcolor; use self::termion::event::Event as TEvent; @@ -43,7 +43,7 @@ pub struct Backend { impl Backend { /// Creates a new termion-based backend. - pub fn init() -> Box { + pub fn init() -> Box { // Use a ~8MB buffer // Should be enough for a single screen most of the time. let terminal = @@ -284,7 +284,7 @@ impl backend::Backend for Backend { fn with_color(clr: &theme::Color, f: F) -> R where - F: FnOnce(&tcolor::Color) -> R, + F: FnOnce(&dyn tcolor::Color) -> R, { match *clr { theme::Color::TerminalDefault => f(&tcolor::Reset), diff --git a/src/cursive.rs b/src/cursive.rs index dd72f94..ef655ea 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -39,17 +39,17 @@ pub struct Cursive { running: bool, - backend: Box, + backend: Box, - cb_source: Receiver>, - cb_sink: Sender>, + cb_source: Receiver>, + cb_sink: Sender>, } /// Identifies a screen in the cursive root. pub type ScreenId = usize; /// Convenient alias to the result of `Cursive::cb_sink`. -pub type CbSink = Sender>; +pub type CbSink = Sender>; /// Asynchronous callback function trait. /// @@ -127,7 +127,7 @@ impl Cursive { /// ``` pub fn new(backend_init: F) -> Self where - F: FnOnce() -> Box, + F: FnOnce() -> Box, { let theme = theme::load_default(); @@ -422,7 +422,7 @@ impl Cursive { /// # } /// ``` pub fn call_on( - &mut self, sel: &view::Selector, callback: F, + &mut self, sel: &view::Selector<'_>, callback: F, ) -> Option where V: View + Any, @@ -522,7 +522,7 @@ impl Cursive { } /// Moves the focus to the view identified by `sel`. - pub fn focus(&mut self, sel: &view::Selector) -> Result<(), ()> { + pub fn focus(&mut self, sel: &view::Selector<'_>) -> Result<(), ()> { self.screen_mut().focus_view(sel) } @@ -604,7 +604,7 @@ impl Cursive { } /// Convenient method to remove a layer from the current screen. - pub fn pop_layer(&mut self) -> Option> { + pub fn pop_layer(&mut self) -> Option> { self.screen_mut().pop_layer() } diff --git a/src/event.rs b/src/event.rs index f760d60..0010670 100644 --- a/src/event.rs +++ b/src/event.rs @@ -23,14 +23,14 @@ use crate::Cursive; /// Callback is a function that can be triggered by an event. /// It has a mutable access to the cursive root. #[derive(Clone)] -pub struct Callback(Rc>); +pub struct Callback(Rc>); // TODO: remove the Box when Box -> Rc is possible /// A boxed callback that can be run on `&mut Any`. -pub type AnyCb<'a> = Box; +pub type AnyCb<'a> = Box; /// A trigger that only selects some types of events. -pub struct EventTrigger(Box bool>); +pub struct EventTrigger(Box bool>); impl EventTrigger { /// Create a new `EventTrigger` using the given function as filter. @@ -148,26 +148,26 @@ impl Callback { } impl Deref for Callback { - type Target = Box; - fn deref<'a>(&'a self) -> &'a Box { + type Target = Box; + fn deref<'a>(&'a self) -> &'a Box { &self.0 } } -impl From>> for Callback { - fn from(f: Rc>) -> Self { +impl From>> for Callback { + fn from(f: Rc>) -> Self { Callback(f) } } -impl From> for Callback { - fn from(f: Box) -> Self { +impl From> for Callback { + fn from(f: Box) -> Self { Callback(Rc::new(f)) } } -impl From> for Callback { - fn from(f: Box) -> Self { +impl From> for Callback { + fn from(f: Box) -> Self { Callback(Rc::new(f)) } } diff --git a/src/lib.rs b/src/lib.rs index db07669..8fe3bc8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -78,17 +78,16 @@ extern crate maplit; // We use chan_signal to detect SIGWINCH. // It's not how windows work, so no need to use that. -#[cfg(unix)] -extern crate signal_hook; -extern crate chrono; -extern crate libc; -extern crate num; -extern crate owning_ref; -extern crate toml; -extern crate unicode_segmentation; -extern crate unicode_width; -extern crate xi_unicode; + + + + + + + + + macro_rules! new_default( ($c:ty) => { diff --git a/src/logger.rs b/src/logger.rs index fa46167..4e9e1d3 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -27,11 +27,11 @@ lazy_static! { } impl log::Log for CursiveLogger { - fn enabled(&self, _metadata: &log::Metadata) -> bool { + fn enabled(&self, _metadata: &log::Metadata<'_>) -> bool { true } - fn log(&self, record: &log::Record) { + fn log(&self, record: &log::Record<'_>) { let mut logs = LOGS.lock().unwrap(); // TODO: customize the format? Use colors? Save more info? if logs.len() == logs.capacity() { diff --git a/src/printer.rs b/src/printer.rs index ab8d0ac..7211000 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -50,7 +50,7 @@ pub struct Printer<'a, 'b> { pub theme: &'a Theme, /// Backend used to actually draw things - backend: &'b Backend, + backend: &'b dyn Backend, } impl<'a, 'b> Printer<'a, 'b> { @@ -59,7 +59,7 @@ impl<'a, 'b> Printer<'a, 'b> { /// But nobody needs to know that. #[doc(hidden)] pub fn new>( - size: T, theme: &'a Theme, backend: &'b Backend, + size: T, theme: &'a Theme, backend: &'b dyn Backend, ) -> Self { let size = size.into(); Printer { @@ -265,7 +265,7 @@ impl<'a, 'b> Printer<'a, 'b> { /// ``` pub fn with_color(&self, c: ColorStyle, f: F) where - F: FnOnce(&Printer), + F: FnOnce(&Printer<'_, '_>), { let old = self.backend.set_color(c.resolve(&self.theme.palette)); f(self); @@ -276,7 +276,7 @@ impl<'a, 'b> Printer<'a, 'b> { /// that will apply the given style on prints. pub fn with_style(&self, style: T, f: F) where - F: FnOnce(&Printer), + F: FnOnce(&Printer<'_, '_>), T: Into