Skip to content
This repository was archived by the owner on Aug 6, 2023. It is now read-only.

Commit 6069d89

Browse files
committedDec 23, 2021
chore: fix all clippy warnings
1 parent d25e263 commit 6069d89

20 files changed

+39
-118
lines changed
 

‎examples/barchart.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,15 @@ fn run_app<B: Backend>(
9494
) -> io::Result<()> {
9595
let mut last_tick = Instant::now();
9696
loop {
97-
terminal.draw(|f| ui(f, &mut app))?;
97+
terminal.draw(|f| ui(f, &app))?;
9898

9999
let timeout = tick_rate
100100
.checked_sub(last_tick.elapsed())
101101
.unwrap_or_else(|| Duration::from_secs(0));
102102
if crossterm::event::poll(timeout)? {
103103
if let Event::Key(key) = event::read()? {
104-
match key.code {
105-
KeyCode::Char('q') => return Ok(()),
106-
_ => {}
104+
if let KeyCode::Char('q') = key.code {
105+
return Ok(());
107106
}
108107
}
109108
}

‎examples/block.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> io::Result<()> {
4545
terminal.draw(ui)?;
4646

4747
if let Event::Key(key) = event::read()? {
48-
match key.code {
49-
KeyCode::Char('q') => return Ok(()),
50-
_ => {}
48+
if let KeyCode::Char('q') = key.code {
49+
return Ok(());
5150
}
5251
}
5352
}

‎examples/chart.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,15 @@ fn run_app<B: Backend>(
130130
) -> io::Result<()> {
131131
let mut last_tick = Instant::now();
132132
loop {
133-
terminal.draw(|f| ui(f, &mut app))?;
133+
terminal.draw(|f| ui(f, &app))?;
134134

135135
let timeout = tick_rate
136136
.checked_sub(last_tick.elapsed())
137137
.unwrap_or_else(|| Duration::from_secs(0));
138138
if crossterm::event::poll(timeout)? {
139139
if let Event::Key(key) = event::read()? {
140-
match key.code {
141-
KeyCode::Char('q') => return Ok(()),
142-
_ => {}
140+
if let KeyCode::Char('q') = key.code {
141+
return Ok(());
143142
}
144143
}
145144
}

‎examples/custom_widget.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@ use tui::{
1313
Frame, Terminal,
1414
};
1515

16+
#[derive(Default)]
1617
struct Label<'a> {
1718
text: &'a str,
1819
}
1920

20-
impl<'a> Default for Label<'a> {
21-
fn default() -> Label<'a> {
22-
Label { text: "" }
23-
}
24-
}
25-
2621
impl<'a> Widget for Label<'a> {
2722
fn render(self, area: Rect, buf: &mut Buffer) {
2823
buf.set_string(area.left(), area.top(), self.text, Style::default());
@@ -68,9 +63,8 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> io::Result<()> {
6863
terminal.draw(ui)?;
6964

7065
if let Event::Key(key) = event::read()? {
71-
match key.code {
72-
KeyCode::Char('q') => return Ok(()),
73-
_ => {}
66+
if let KeyCode::Char('q') = key.code {
67+
return Ok(());
7468
}
7569
}
7670
}

‎examples/demo/termion.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@ fn events(tick_rate: Duration) -> mpsc::Receiver<Event> {
6262
let keys_tx = tx.clone();
6363
thread::spawn(move || {
6464
let stdin = io::stdin();
65-
for evt in stdin.keys() {
66-
if let Ok(key) = evt {
67-
if let Err(err) = keys_tx.send(Event::Input(key)) {
68-
eprintln!("{}", err);
69-
return;
70-
}
65+
for key in stdin.keys().flatten() {
66+
if let Err(err) = keys_tx.send(Event::Input(key)) {
67+
eprintln!("{}", err);
68+
return;
7169
}
7270
}
7371
});

‎examples/gauge.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,15 @@ fn run_app<B: Backend>(
9090
) -> io::Result<()> {
9191
let mut last_tick = Instant::now();
9292
loop {
93-
terminal.draw(|f| ui(f, &mut app))?;
93+
terminal.draw(|f| ui(f, &app))?;
9494

9595
let timeout = tick_rate
9696
.checked_sub(last_tick.elapsed())
9797
.unwrap_or_else(|| Duration::from_secs(0));
9898
if crossterm::event::poll(timeout)? {
9999
if let Event::Key(key) = event::read()? {
100-
match key.code {
101-
KeyCode::Char('q') => return Ok(()),
102-
_ => {}
100+
if let KeyCode::Char('q') = key.code {
101+
return Ok(());
103102
}
104103
}
105104
}

‎examples/layout.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ fn run_app<B: Backend>(terminal: &mut Terminal<B>) -> io::Result<()> {
4343
terminal.draw(|f| ui(f))?;
4444

4545
if let Event::Key(key) = event::read()? {
46-
match key.code {
47-
KeyCode::Char('q') => return Ok(()),
48-
_ => {}
46+
if let KeyCode::Char('q') = key.code {
47+
return Ok(());
4948
}
5049
}
5150
}

‎examples/paragraph.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,15 @@ fn run_app<B: Backend>(
6868
) -> io::Result<()> {
6969
let mut last_tick = Instant::now();
7070
loop {
71-
terminal.draw(|f| ui(f, &mut app))?;
71+
terminal.draw(|f| ui(f, &app))?;
7272

7373
let timeout = tick_rate
7474
.checked_sub(last_tick.elapsed())
7575
.unwrap_or_else(|| Duration::from_secs(0));
7676
if crossterm::event::poll(timeout)? {
7777
if let Event::Key(key) = event::read()? {
78-
match key.code {
79-
KeyCode::Char('q') => return Ok(()),
80-
_ => {}
78+
if let KeyCode::Char('q') = key.code {
79+
return Ok(());
8180
}
8281
}
8382
}

‎examples/popup.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn main() -> Result<(), Box<dyn Error>> {
5454

5555
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
5656
loop {
57-
terminal.draw(|f| ui(f, &mut app))?;
57+
terminal.draw(|f| ui(f, &app))?;
5858

5959
if let Event::Key(key) = event::read()? {
6060
match key.code {

‎examples/sparkline.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,15 @@ fn run_app<B: Backend>(
112112
) -> io::Result<()> {
113113
let mut last_tick = Instant::now();
114114
loop {
115-
terminal.draw(|f| ui(f, &mut app))?;
115+
terminal.draw(|f| ui(f, &app))?;
116116

117117
let timeout = tick_rate
118118
.checked_sub(last_tick.elapsed())
119119
.unwrap_or_else(|| Duration::from_secs(0));
120120
if crossterm::event::poll(timeout)? {
121121
if let Event::Key(key) = event::read()? {
122-
match key.code {
123-
KeyCode::Char('q') => return Ok(()),
124-
_ => {}
122+
if let KeyCode::Char('q') = key.code {
123+
return Ok(());
125124
}
126125
}
127126
}

‎examples/tabs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn main() -> Result<(), Box<dyn Error>> {
6969

7070
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
7171
loop {
72-
terminal.draw(|f| ui(f, &mut app))?;
72+
terminal.draw(|f| ui(f, &app))?;
7373

7474
if let Event::Key(key) = event::read()? {
7575
match key.code {

‎examples/user_input.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn main() -> Result<(), Box<dyn Error>> {
8080

8181
fn run_app<B: Backend>(terminal: &mut Terminal<B>, mut app: App) -> io::Result<()> {
8282
loop {
83-
terminal.draw(|f| ui(f, &mut app))?;
83+
terminal.draw(|f| ui(f, &app))?;
8484

8585
if let Event::Key(key) = event::read()? {
8686
match app.input_mode {

‎src/buffer.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl Default for Cell {
105105
/// buf.get_mut(5, 0).set_char('x');
106106
/// assert_eq!(buf.get(5, 0).symbol, "x");
107107
/// ```
108-
#[derive(Debug, Clone, PartialEq)]
108+
#[derive(Debug, Clone, PartialEq, Default)]
109109
pub struct Buffer {
110110
/// The area represented by this buffer
111111
pub area: Rect,
@@ -114,15 +114,6 @@ pub struct Buffer {
114114
pub content: Vec<Cell>,
115115
}
116116

117-
impl Default for Buffer {
118-
fn default() -> Buffer {
119-
Buffer {
120-
area: Default::default(),
121-
content: Vec::new(),
122-
}
123-
}
124-
}
125-
126117
impl Buffer {
127118
/// Returns a Buffer with all cells set to the default one
128119
pub fn empty(area: Rect) -> Buffer {

‎src/layout.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -363,25 +363,14 @@ impl Element {
363363

364364
/// A simple rectangle used in the computation of the layout and to give widgets an hint about the
365365
/// area they are supposed to render to.
366-
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
366+
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Default)]
367367
pub struct Rect {
368368
pub x: u16,
369369
pub y: u16,
370370
pub width: u16,
371371
pub height: u16,
372372
}
373373

374-
impl Default for Rect {
375-
fn default() -> Rect {
376-
Rect {
377-
x: 0,
378-
y: 0,
379-
width: 0,
380-
height: 0,
381-
}
382-
}
383-
}
384-
385374
impl Rect {
386375
/// Creates a new rect, with width and height limited to keep the area under max u16.
387376
/// If clipped, aspect ratio will be preserved.

‎src/text.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,9 @@ impl<'a> From<&'a str> for Span<'a> {
194194
}
195195

196196
/// A string composed of clusters of graphemes, each with their own style.
197-
#[derive(Debug, Clone, PartialEq)]
197+
#[derive(Debug, Clone, PartialEq, Default)]
198198
pub struct Spans<'a>(pub Vec<Span<'a>>);
199199

200-
impl<'a> Default for Spans<'a> {
201-
fn default() -> Spans<'a> {
202-
Spans(Vec::new())
203-
}
204-
}
205-
206200
impl<'a> Spans<'a> {
207201
/// Returns the width of the underlying string.
208202
///
@@ -279,17 +273,11 @@ impl<'a> From<Spans<'a>> for String {
279273
/// text.extend(Text::styled("Some more lines\nnow with more style!", style));
280274
/// assert_eq!(6, text.height());
281275
/// ```
282-
#[derive(Debug, Clone, PartialEq)]
276+
#[derive(Debug, Clone, PartialEq, Default)]
283277
pub struct Text<'a> {
284278
pub lines: Vec<Spans<'a>>,
285279
}
286280

287-
impl<'a> Default for Text<'a> {
288-
fn default() -> Text<'a> {
289-
Text { lines: Vec::new() }
290-
}
291-
}
292-
293281
impl<'a> Text<'a> {
294282
/// Create some text (potentially multiple lines) with no style.
295283
///

‎src/widgets/canvas/world.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6122,6 +6122,7 @@ pub static WORLD_LOW_RESOLUTION: [(f64, f64); 1166] = [
61226122
(120.43, 16.43),
61236123
(121.72, 18.40),
61246124
(125.34, 9.79),
6125+
#[allow(clippy::approx_constant)]
61256126
(125.56, 6.28),
61266127
(122.38, 7.00),
61276128
(125.10, 9.38),

‎src/widgets/chart.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'a> Dataset<'a> {
141141

142142
/// A container that holds all the infos about where to display each elements of the chart (axis,
143143
/// labels, legend, ...).
144-
#[derive(Debug, Clone, PartialEq)]
144+
#[derive(Debug, Clone, PartialEq, Default)]
145145
struct ChartLayout {
146146
/// Location of the title of the x axis
147147
title_x: Option<(u16, u16)>,
@@ -161,21 +161,6 @@ struct ChartLayout {
161161
graph_area: Rect,
162162
}
163163

164-
impl Default for ChartLayout {
165-
fn default() -> ChartLayout {
166-
ChartLayout {
167-
title_x: None,
168-
title_y: None,
169-
label_x: None,
170-
label_y: None,
171-
axis_x: None,
172-
axis_y: None,
173-
legend_area: None,
174-
graph_area: Rect::default(),
175-
}
176-
}
177-
}
178-
179164
/// A widget to plot one or more dataset in a cartesian coordinate system
180165
///
181166
/// # Examples

‎src/widgets/list.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,12 @@ use crate::{
77
};
88
use unicode_width::UnicodeWidthStr;
99

10-
#[derive(Debug, Clone)]
10+
#[derive(Debug, Clone, Default)]
1111
pub struct ListState {
1212
offset: usize,
1313
selected: Option<usize>,
1414
}
1515

16-
impl Default for ListState {
17-
fn default() -> ListState {
18-
ListState {
19-
offset: 0,
20-
selected: None,
21-
}
22-
}
23-
}
24-
2516
impl ListState {
2617
pub fn selected(&self) -> Option<usize> {
2718
self.selected

‎src/widgets/reflow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,8 @@ mod test {
403403
let text = "コンピュータ上で文字を扱う場合、典型的には文字による通信を行う場合にその両端点\
404404
では、";
405405
let (word_wrapper, word_wrapper_width) =
406-
run_composer(Composer::WordWrapper { trim: true }, &text, width);
407-
let (line_truncator, _) = run_composer(Composer::LineTruncator, &text, width);
406+
run_composer(Composer::WordWrapper { trim: true }, text, width);
407+
let (line_truncator, _) = run_composer(Composer::LineTruncator, text, width);
408408
assert_eq!(line_truncator, vec!["コンピュータ上で文字"]);
409409
let wrapped = vec![
410410
"コンピュータ上で文字",

‎src/widgets/table.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -335,21 +335,12 @@ impl<'a> Table<'a> {
335335
}
336336
}
337337

338-
#[derive(Debug, Clone)]
338+
#[derive(Debug, Clone, Default)]
339339
pub struct TableState {
340340
offset: usize,
341341
selected: Option<usize>,
342342
}
343343

344-
impl Default for TableState {
345-
fn default() -> TableState {
346-
TableState {
347-
offset: 0,
348-
selected: None,
349-
}
350-
}
351-
}
352-
353344
impl TableState {
354345
pub fn selected(&self) -> Option<usize> {
355346
self.selected

0 commit comments

Comments
 (0)
This repository has been archived.