From a3551718447d9bce69fc3d8702a88939f8542b15 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Tue, 10 Apr 2018 11:53:25 -0700 Subject: [PATCH] Fix clippy warnings --- src/backend/curses/n.rs | 5 +++-- src/cursive.rs | 2 +- src/printer.rs | 8 ++++---- src/view/margins.rs | 29 ++++++++++++++++++----------- src/view/size_cache.rs | 6 +++--- src/views/box_view.rs | 2 +- src/views/canvas.rs | 2 +- src/views/linear_layout.rs | 2 +- src/views/menu_popup.rs | 2 +- src/views/on_event_view.rs | 2 +- src/views/panel.rs | 2 +- src/views/radio.rs | 6 +++--- src/views/select_view.rs | 2 +- src/xy.rs | 2 +- 14 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index dac09bb..6b9b684 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -159,7 +159,7 @@ impl Backend { let make_event = |event| Event::Mouse { offset: Vec2::zero(), position: Vec2::new(mevent.x as usize, mevent.y as usize), - event: event, + event, }; if mevent.bstate == ncurses::REPORT_MOUSE_POSITION as mmask_t { @@ -239,7 +239,8 @@ impl backend::Backend for Backend { if current != colors { self.set_colors(colors); } - return current; + + current } fn set_effect(&self, effect: Effect) { diff --git a/src/cursive.rs b/src/cursive.rs index 3b2f314..784d0ac 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -569,7 +569,7 @@ impl Cursive { } let printer = - Printer::new(self.screen_size(), &self.theme, &self.backend); + Printer::new(self.screen_size(), &self.theme, &*self.backend); let selected = self.menubar.receive_events(); diff --git a/src/printer.rs b/src/printer.rs index ab4547d..0b8c3fe 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -24,7 +24,7 @@ pub struct Printer<'a> { /// `true` if nothing has been drawn yet. new: Rc>, /// Backend used to actually draw things - backend: &'a Box, + backend: &'a Backend, } impl<'a> Printer<'a> { @@ -33,15 +33,15 @@ impl<'a> Printer<'a> { /// But nobody needs to know that. #[doc(hidden)] pub fn new>( - size: T, theme: &'a Theme, backend: &'a Box + size: T, theme: &'a Theme, backend: &'a Backend ) -> Self { Printer { offset: Vec2::zero(), size: size.into(), focused: true, - theme: theme, + theme, new: Rc::new(Cell::new(true)), - backend: backend, + backend, } } diff --git a/src/view/margins.rs b/src/view/margins.rs index 4772b7e..e358bda 100644 --- a/src/view/margins.rs +++ b/src/view/margins.rs @@ -1,5 +1,5 @@ -use vec::Vec2; use std::ops::{Add, Div, Mul, Sub}; +use vec::Vec2; /// Four values representing each direction. #[derive(Clone, Copy)] @@ -18,10 +18,10 @@ impl Margins { /// Creates a new Margins. pub fn new(left: usize, right: usize, top: usize, bottom: usize) -> Self { Margins { - left: left, - right: right, - top: top, - bottom: bottom, + left, + right, + top, + bottom, } } @@ -52,25 +52,34 @@ impl Margins { } impl From<(usize, usize, usize, usize)> for Margins { - fn from((left, right, top, bottom): (usize, usize, usize, usize)) -> Margins { + fn from( + (left, right, top, bottom): (usize, usize, usize, usize), + ) -> Margins { Margins::new(left, right, top, bottom) } } impl From<(i32, i32, i32, i32)> for Margins { fn from((left, right, top, bottom): (i32, i32, i32, i32)) -> Margins { - (left as usize, right as usize, top as usize, bottom as usize).into() + ( + left as usize, + right as usize, + top as usize, + bottom as usize, + ).into() } } impl From<((i32, i32), (i32, i32))> for Margins { - fn from(((left, right), (top, bottom)): ((i32, i32), (i32, i32))) -> Margins { + fn from( + ((left, right), (top, bottom)): ((i32, i32), (i32, i32)), + ) -> Margins { (left, right, top, bottom).into() } } impl From<((usize, usize), (usize, usize))> for Margins { fn from( - ((left, right), (top, bottom)): ((usize, usize), (usize, usize)) + ((left, right), (top, bottom)): ((usize, usize), (usize, usize)), ) -> Margins { (left, right, top, bottom).into() } @@ -131,5 +140,3 @@ impl Mul for Margins { } } } - - diff --git a/src/view/size_cache.rs b/src/view/size_cache.rs index 021a6b3..3786eab 100644 --- a/src/view/size_cache.rs +++ b/src/view/size_cache.rs @@ -1,5 +1,5 @@ -use XY; use vec::Vec2; +use XY; /// Cache around a one-dimensional layout result. /// @@ -19,8 +19,8 @@ impl SizeCache { /// Creates a new sized cache pub fn new(value: usize, constrained: bool) -> Self { SizeCache { - value: value, - constrained: constrained, + value, + constrained, } } diff --git a/src/views/box_view.rs b/src/views/box_view.rs index 48cfaa1..af55c6a 100644 --- a/src/views/box_view.rs +++ b/src/views/box_view.rs @@ -44,7 +44,7 @@ impl BoxView { BoxView { size: (width, height).into(), squishable: false, - view: view, + view, } } diff --git a/src/views/canvas.rs b/src/views/canvas.rs index 8d5d7af..f89be69 100644 --- a/src/views/canvas.rs +++ b/src/views/canvas.rs @@ -48,7 +48,7 @@ impl Canvas { /// ``` pub fn new(state: T) -> Self { Canvas { - state: state, + state, draw: Box::new(|_, _| ()), on_event: Box::new(|_, _| EventResult::Ignored), required_size: Box::new(|_, _| Vec2::new(1, 1)), diff --git a/src/views/linear_layout.rs b/src/views/linear_layout.rs index 605903a..1dc406f 100644 --- a/src/views/linear_layout.rs +++ b/src/views/linear_layout.rs @@ -113,7 +113,7 @@ impl LinearLayout { pub fn new(orientation: direction::Orientation) -> Self { LinearLayout { children: Vec::new(), - orientation: orientation, + orientation, focus: 0, cache: None, } diff --git a/src/views/menu_popup.rs b/src/views/menu_popup.rs index f583a3e..e255a09 100644 --- a/src/views/menu_popup.rs +++ b/src/views/menu_popup.rs @@ -26,7 +26,7 @@ impl MenuPopup { /// Creates a new `MenuPopup` using the given menu tree. pub fn new(menu: Rc) -> Self { MenuPopup { - menu: menu, + menu, focus: 0, scrollbase: ScrollBase::new().scrollbar_offset(1).right_padding(0), align: Align::top_left(), diff --git a/src/views/on_event_view.rs b/src/views/on_event_view.rs index e7a7e03..4db522a 100644 --- a/src/views/on_event_view.rs +++ b/src/views/on_event_view.rs @@ -72,7 +72,7 @@ impl OnEventView { /// Wraps the given view in a new OnEventView. pub fn new(view: T) -> Self { OnEventView { - view: view, + view, callbacks: HashMap::new(), } } diff --git a/src/views/panel.rs b/src/views/panel.rs index 07627fb..63e577f 100644 --- a/src/views/panel.rs +++ b/src/views/panel.rs @@ -12,7 +12,7 @@ pub struct Panel { impl Panel { /// Creates a new panel around the given view. pub fn new(view: V) -> Self { - Panel { view: view } + Panel { view } } inner_getters!(self.view: V); diff --git a/src/views/radio.rs b/src/views/radio.rs index 15cd4e3..9afb823 100644 --- a/src/views/radio.rs +++ b/src/views/radio.rs @@ -107,10 +107,10 @@ impl RadioButton { state: Rc>>, id: usize, label: String ) -> Self { RadioButton { - state: state, - id: id, + state, + id, enabled: true, - label: label, + label, } } diff --git a/src/views/select_view.rs b/src/views/select_view.rs index 9cf704d..edc44e8 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -341,7 +341,7 @@ impl SelectView { // TODO: Check if `i >= self.len()` ? // assert!(i < self.len(), "SelectView: trying to select out-of-bound"); // Or just cap the ID? - let i = if self.len() == 0 { + let i = if self.is_empty() { 0 } else { min(i, self.len() - 1) diff --git a/src/xy.rs b/src/xy.rs index 35e2f20..9c73b5b 100644 --- a/src/xy.rs +++ b/src/xy.rs @@ -13,7 +13,7 @@ pub struct XY { impl XY { /// Creates a new `XY` from the given values. pub fn new(x: T, y: T) -> Self { - XY { x: x, y: y } + XY { x, y } } /// Creates a new `XY` by applying `f` to `x` and `y`.