Fix clippy warnings

This commit is contained in:
Alexandre Bury 2018-04-10 11:53:25 -07:00
parent b1e9afe0ff
commit a355171844
14 changed files with 40 additions and 32 deletions

View File

@ -159,7 +159,7 @@ impl Backend {
let make_event = |event| Event::Mouse { let make_event = |event| Event::Mouse {
offset: Vec2::zero(), offset: Vec2::zero(),
position: Vec2::new(mevent.x as usize, mevent.y as usize), position: Vec2::new(mevent.x as usize, mevent.y as usize),
event: event, event,
}; };
if mevent.bstate == ncurses::REPORT_MOUSE_POSITION as mmask_t { if mevent.bstate == ncurses::REPORT_MOUSE_POSITION as mmask_t {
@ -239,7 +239,8 @@ impl backend::Backend for Backend {
if current != colors { if current != colors {
self.set_colors(colors); self.set_colors(colors);
} }
return current;
current
} }
fn set_effect(&self, effect: Effect) { fn set_effect(&self, effect: Effect) {

View File

@ -569,7 +569,7 @@ impl Cursive {
} }
let printer = 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(); let selected = self.menubar.receive_events();

View File

@ -24,7 +24,7 @@ pub struct Printer<'a> {
/// `true` if nothing has been drawn yet. /// `true` if nothing has been drawn yet.
new: Rc<Cell<bool>>, new: Rc<Cell<bool>>,
/// Backend used to actually draw things /// Backend used to actually draw things
backend: &'a Box<Backend>, backend: &'a Backend,
} }
impl<'a> Printer<'a> { impl<'a> Printer<'a> {
@ -33,15 +33,15 @@ impl<'a> Printer<'a> {
/// But nobody needs to know that. /// But nobody needs to know that.
#[doc(hidden)] #[doc(hidden)]
pub fn new<T: Into<Vec2>>( pub fn new<T: Into<Vec2>>(
size: T, theme: &'a Theme, backend: &'a Box<Backend> size: T, theme: &'a Theme, backend: &'a Backend
) -> Self { ) -> Self {
Printer { Printer {
offset: Vec2::zero(), offset: Vec2::zero(),
size: size.into(), size: size.into(),
focused: true, focused: true,
theme: theme, theme,
new: Rc::new(Cell::new(true)), new: Rc::new(Cell::new(true)),
backend: backend, backend,
} }
} }

View File

@ -1,5 +1,5 @@
use vec::Vec2;
use std::ops::{Add, Div, Mul, Sub}; use std::ops::{Add, Div, Mul, Sub};
use vec::Vec2;
/// Four values representing each direction. /// Four values representing each direction.
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
@ -18,10 +18,10 @@ impl Margins {
/// Creates a new Margins. /// Creates a new Margins.
pub fn new(left: usize, right: usize, top: usize, bottom: usize) -> Self { pub fn new(left: usize, right: usize, top: usize, bottom: usize) -> Self {
Margins { Margins {
left: left, left,
right: right, right,
top: top, top,
bottom: bottom, bottom,
} }
} }
@ -52,25 +52,34 @@ impl Margins {
} }
impl From<(usize, usize, usize, usize)> for 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) Margins::new(left, right, top, bottom)
} }
} }
impl From<(i32, i32, i32, i32)> for Margins { 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 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 { 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() (left, right, top, bottom).into()
} }
} }
impl From<((usize, usize), (usize, usize))> for Margins { impl From<((usize, usize), (usize, usize))> for Margins {
fn from( fn from(
((left, right), (top, bottom)): ((usize, usize), (usize, usize)) ((left, right), (top, bottom)): ((usize, usize), (usize, usize)),
) -> Margins { ) -> Margins {
(left, right, top, bottom).into() (left, right, top, bottom).into()
} }
@ -131,5 +140,3 @@ impl Mul<usize> for Margins {
} }
} }
} }

View File

@ -1,5 +1,5 @@
use XY;
use vec::Vec2; use vec::Vec2;
use XY;
/// Cache around a one-dimensional layout result. /// Cache around a one-dimensional layout result.
/// ///
@ -19,8 +19,8 @@ impl SizeCache {
/// Creates a new sized cache /// Creates a new sized cache
pub fn new(value: usize, constrained: bool) -> Self { pub fn new(value: usize, constrained: bool) -> Self {
SizeCache { SizeCache {
value: value, value,
constrained: constrained, constrained,
} }
} }

View File

@ -44,7 +44,7 @@ impl<T: View> BoxView<T> {
BoxView { BoxView {
size: (width, height).into(), size: (width, height).into(),
squishable: false, squishable: false,
view: view, view,
} }
} }

View File

@ -48,7 +48,7 @@ impl<T> Canvas<T> {
/// ``` /// ```
pub fn new(state: T) -> Self { pub fn new(state: T) -> Self {
Canvas { Canvas {
state: state, state,
draw: Box::new(|_, _| ()), draw: Box::new(|_, _| ()),
on_event: Box::new(|_, _| EventResult::Ignored), on_event: Box::new(|_, _| EventResult::Ignored),
required_size: Box::new(|_, _| Vec2::new(1, 1)), required_size: Box::new(|_, _| Vec2::new(1, 1)),

View File

@ -113,7 +113,7 @@ impl LinearLayout {
pub fn new(orientation: direction::Orientation) -> Self { pub fn new(orientation: direction::Orientation) -> Self {
LinearLayout { LinearLayout {
children: Vec::new(), children: Vec::new(),
orientation: orientation, orientation,
focus: 0, focus: 0,
cache: None, cache: None,
} }

View File

@ -26,7 +26,7 @@ impl MenuPopup {
/// Creates a new `MenuPopup` using the given menu tree. /// Creates a new `MenuPopup` using the given menu tree.
pub fn new(menu: Rc<MenuTree>) -> Self { pub fn new(menu: Rc<MenuTree>) -> Self {
MenuPopup { MenuPopup {
menu: menu, menu,
focus: 0, focus: 0,
scrollbase: ScrollBase::new().scrollbar_offset(1).right_padding(0), scrollbase: ScrollBase::new().scrollbar_offset(1).right_padding(0),
align: Align::top_left(), align: Align::top_left(),

View File

@ -72,7 +72,7 @@ impl<T: View> OnEventView<T> {
/// Wraps the given view in a new OnEventView. /// Wraps the given view in a new OnEventView.
pub fn new(view: T) -> Self { pub fn new(view: T) -> Self {
OnEventView { OnEventView {
view: view, view,
callbacks: HashMap::new(), callbacks: HashMap::new(),
} }
} }

View File

@ -12,7 +12,7 @@ pub struct Panel<V: View> {
impl<V: View> Panel<V> { impl<V: View> Panel<V> {
/// Creates a new panel around the given view. /// Creates a new panel around the given view.
pub fn new(view: V) -> Self { pub fn new(view: V) -> Self {
Panel { view: view } Panel { view }
} }
inner_getters!(self.view: V); inner_getters!(self.view: V);

View File

@ -107,10 +107,10 @@ impl<T> RadioButton<T> {
state: Rc<RefCell<SharedState<T>>>, id: usize, label: String state: Rc<RefCell<SharedState<T>>>, id: usize, label: String
) -> Self { ) -> Self {
RadioButton { RadioButton {
state: state, state,
id: id, id,
enabled: true, enabled: true,
label: label, label,
} }
} }

View File

@ -341,7 +341,7 @@ impl<T: 'static> SelectView<T> {
// TODO: Check if `i >= self.len()` ? // TODO: Check if `i >= self.len()` ?
// assert!(i < self.len(), "SelectView: trying to select out-of-bound"); // assert!(i < self.len(), "SelectView: trying to select out-of-bound");
// Or just cap the ID? // Or just cap the ID?
let i = if self.len() == 0 { let i = if self.is_empty() {
0 0
} else { } else {
min(i, self.len() - 1) min(i, self.len() - 1)

View File

@ -13,7 +13,7 @@ pub struct XY<T> {
impl<T> XY<T> { impl<T> XY<T> {
/// Creates a new `XY` from the given values. /// Creates a new `XY` from the given values.
pub fn new(x: T, y: T) -> Self { 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`. /// Creates a new `XY` by applying `f` to `x` and `y`.