From 759f57f1f894c973046c7926fb95a2a29ac2faf3 Mon Sep 17 00:00:00 2001 From: Peter Kloss Date: Wed, 11 Oct 2017 18:09:49 +0200 Subject: [PATCH] fix some clippy warnings --- examples/progress.rs | 2 +- src/backend/curses/mod.rs | 8 ++++---- src/backend/curses/n.rs | 2 +- src/utf8.rs | 4 ++-- src/views/edit_view.rs | 11 +++++++++-- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/examples/progress.rs b/examples/progress.rs index 3a83235..7dc77fb 100644 --- a/examples/progress.rs +++ b/examples/progress.rs @@ -78,7 +78,7 @@ fn phase_2(s: &mut Cursive) { let speeds: Vec<_> = (0..n_bars).map(|_| rand::thread_rng().gen_range(50, 150)).collect(); - let n_max = 100000; + let n_max = 100_000; let cb = s.cb_sink().clone(); // Let's prepare the progress bars... diff --git a/src/backend/curses/mod.rs b/src/backend/curses/mod.rs index 1fa5260..0c1264c 100644 --- a/src/backend/curses/mod.rs +++ b/src/backend/curses/mod.rs @@ -31,11 +31,11 @@ fn find_closest(color: &Color) -> i16 { Color::Light(BaseColor::Cyan) => 14, Color::Light(BaseColor::White) => 15, Color::Rgb(r, g, b) => { - let r = 6 * r as u16 / 256; - let g = 6 * g as u16 / 256; - let b = 6 * b as u16 / 256; + let r = 6 * u16::from(r) / 256; + let g = 6 * u16::from(g) / 256; + let b = 6 * u16::from(b) / 256; (16 + 36 * r + 6 * g + b) as i16 } - Color::RgbLowRes(r, g, b) => (16 + 36 * r + 6 * g + b) as i16, + Color::RgbLowRes(r, g, b) => i16::from(16 + 36 * r + 6 * g + b), } } diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index 20538a7..9d562d6 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -20,7 +20,7 @@ impl Concrete { -> i16 { let n = 1 + pairs.len() as i16; - let target = if ncurses::COLOR_PAIRS() > n as i32 { + let target = if ncurses::COLOR_PAIRS() > i32::from(n) { // We still have plenty of space for everyone. n } else { diff --git a/src/utf8.rs b/src/utf8.rs index 7b6a6ce..3eae028 100644 --- a/src/utf8.rs +++ b/src/utf8.rs @@ -25,7 +25,7 @@ pub fn read_char(first: u8, next: F) -> Result let mut res = 0u32; // First, get the data - only the few last bits - res |= (first & make_mask(7 - n_bytes)) as u32; + res |= u32::from(first & make_mask(7 - n_bytes)); // We already have one byte, now read the others. for _ in 1..n_bytes { @@ -39,7 +39,7 @@ pub fn read_char(first: u8, next: F) -> Result // We have 6 fresh new bits to read, make room. res <<= 6; // 0x3F is 00111111, so we keep the last 6 bits - res |= (byte & 0x3F) as u32; + res |= u32::from(byte & 0x3F); } // from_u32 could return an error if we gave it invalid utf-8. diff --git a/src/views/edit_view.rs b/src/views/edit_view.rs index 52425bc..816ae1c 100644 --- a/src/views/edit_view.rs +++ b/src/views/edit_view.rs @@ -13,6 +13,13 @@ use utils::simple_suffix; use vec::Vec2; use view::View; +/// closure type for callbacks when the content is modified. Arguments are the +/// `Cursive`, current content of the input and cursor position +pub type OnEdit = Fn(&mut Cursive, &str, usize); + +/// closure type for callbacks when Enter is pressed. Arguments are the `Cursive` +/// and the content of the input. +pub type OnSubmit = Fn(&mut Cursive, &str); /// Input box where the user can enter and edit text. /// @@ -75,10 +82,10 @@ pub struct EditView { /// Callback when the content is modified. /// /// Will be called with the current content and the cursor position. - on_edit: Option>, + on_edit: Option>, /// Callback when is pressed. - on_submit: Option>, + on_submit: Option>, /// When `true`, only print `*` instead of the true content. secret: bool,