Skip to content

Commit 15fb764

Browse files
committed
fix many clippy lints
1 parent ad1ba81 commit 15fb764

File tree

14 files changed

+94
-93
lines changed

14 files changed

+94
-93
lines changed

src/access_point.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl AccessPoint {
222222
self.connected_devices = diagnostic
223223
.iter()
224224
.map(|v| v["Address"].clone().trim_matches('"').to_string())
225-
.collect()
225+
.collect();
226226
}
227227
}
228228

@@ -232,12 +232,12 @@ impl AccessPoint {
232232
pub async fn scan(&self, sender: UnboundedSender<Event>) -> AppResult<()> {
233233
let iwd_access_point = self.session.access_point().unwrap();
234234
match iwd_access_point.scan().await {
235-
Ok(_) => Notification::send(
235+
Ok(()) => Notification::send(
236236
"Start Scanning".to_string(),
237237
NotificationLevel::Info,
238-
sender,
238+
&sender,
239239
)?,
240-
Err(e) => Notification::send(e.to_string(), NotificationLevel::Error, sender.clone())?,
240+
Err(e) => Notification::send(e.to_string(), NotificationLevel::Error, &sender.clone())?,
241241
}
242242

243243
Ok(())
@@ -249,12 +249,12 @@ impl AccessPoint {
249249
.start(self.ssid.value(), self.psk.value())
250250
.await
251251
{
252-
Ok(_) => Notification::send(
252+
Ok(()) => Notification::send(
253253
format!("AP Started\nSSID: {}", self.ssid.value()),
254254
NotificationLevel::Info,
255-
sender,
255+
&sender,
256256
)?,
257-
Err(e) => Notification::send(e.to_string(), NotificationLevel::Error, sender.clone())?,
257+
Err(e) => Notification::send(e.to_string(), NotificationLevel::Error, &sender.clone())?,
258258
}
259259
self.ap_start
260260
.store(false, std::sync::atomic::Ordering::Relaxed);
@@ -265,8 +265,10 @@ impl AccessPoint {
265265
pub async fn stop(&self, sender: UnboundedSender<Event>) -> AppResult<()> {
266266
let iwd_access_point = self.session.access_point().unwrap();
267267
match iwd_access_point.stop().await {
268-
Ok(_) => Notification::send("AP Stopped".to_string(), NotificationLevel::Info, sender)?,
269-
Err(e) => Notification::send(e.to_string(), NotificationLevel::Error, sender.clone())?,
268+
Ok(()) => {
269+
Notification::send("AP Stopped".to_string(), NotificationLevel::Info, &sender)?
270+
}
271+
Err(e) => Notification::send(e.to_string(), NotificationLevel::Error, &sender.clone())?,
270272
}
271273

272274
Ok(())

src/adapter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl Adapter {
226226
let ap_frequency = match self.device.access_point.as_ref() {
227227
Some(ap) => {
228228
if ap.has_started {
229-
format!("{:.2} GHz", (ap.frequency.unwrap() as f32 / 1000.0))
229+
format!("{:.2} GHz", (ap.frequency.unwrap() / 1000))
230230
} else {
231231
"-".to_string()
232232
}
@@ -1034,14 +1034,14 @@ impl Adapter {
10341034
rows.push(Row::new(vec![
10351035
Cell::from("model").style(Style::default().bold().yellow()),
10361036
Cell::from(model.clone()),
1037-
]))
1037+
]));
10381038
}
10391039

10401040
if let Some(vendor) = &self.vendor {
10411041
rows.push(Row::new(vec![
10421042
Cell::from("vendor").style(Style::default().bold().yellow()),
10431043
Cell::from(vendor.clone()),
1044-
]))
1044+
]));
10451045
}
10461046

10471047
let widths = [Constraint::Length(20), Constraint::Fill(1)];

src/app.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub async fn request_confirmation(
8080

8181
r = rx_cancel.recv() => {
8282
match r {
83-
Ok(_) => {
83+
Ok(()) => {
8484
Err(anyhow!("Operation Canceled").into())},
8585
Err(_) => Err(anyhow!("Failed to receive cancel signal").into()),
8686
}
@@ -138,8 +138,7 @@ impl App {
138138

139139
let color_mode = match terminal_light::luma() {
140140
Ok(luma) if luma > 0.6 => ColorMode::Light,
141-
Ok(_) => ColorMode::Dark,
142-
Err(_) => ColorMode::Dark,
141+
Ok(_) | Err(_) => ColorMode::Dark,
143142
};
144143

145144
Ok(Self {

src/device.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Device {
3737
Notification::send(
3838
e.to_string(),
3939
crate::notification::NotificationLevel::Error,
40-
sender.clone(),
40+
&sender.clone(),
4141
)?;
4242
None
4343
}
@@ -52,7 +52,7 @@ impl Device {
5252
Notification::send(
5353
e.to_string(),
5454
crate::notification::NotificationLevel::Error,
55-
sender,
55+
&sender,
5656
)?;
5757
None
5858
}
@@ -110,7 +110,7 @@ impl Device {
110110
Notification::send(
111111
e.to_string(),
112112
crate::notification::NotificationLevel::Error,
113-
sender,
113+
&sender,
114114
)?;
115115
None
116116
}
@@ -132,7 +132,7 @@ impl Device {
132132
Notification::send(
133133
e.to_string(),
134134
crate::notification::NotificationLevel::Error,
135-
sender,
135+
&sender,
136136
)?;
137137
None
138138
}

src/event.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,29 @@ impl EventHandler {
2929
pub fn new(tick_rate: u64) -> Self {
3030
let tick_rate = Duration::from_millis(tick_rate);
3131
let (sender, receiver) = mpsc::unbounded_channel();
32-
let _sender = sender.clone();
32+
let sender_cloned = sender.clone();
3333
let handler = tokio::spawn(async move {
3434
let mut reader = crossterm::event::EventStream::new();
3535
let mut tick = tokio::time::interval(tick_rate);
3636
loop {
3737
let tick_delay = tick.tick();
3838
let crossterm_event = reader.next().fuse();
3939
tokio::select! {
40-
_ = _sender.closed() => {
40+
() = sender_cloned.closed() => {
4141
break;
4242
}
4343
_ = tick_delay => {
44-
_sender.send(Event::Tick).unwrap();
44+
sender_cloned.send(Event::Tick).unwrap();
4545
}
4646
Some(Ok(evt)) = crossterm_event => {
4747
match evt {
4848
CrosstermEvent::Key(key) => {
4949
if key.kind == crossterm::event::KeyEventKind::Press {
50-
_sender.send(Event::Key(key)).unwrap();
50+
sender_cloned.send(Event::Key(key)).unwrap();
5151
}
5252
},
5353
CrosstermEvent::Resize(x, y) => {
54-
_sender.send(Event::Resize(x, y)).unwrap();
54+
sender_cloned.send(Event::Resize(x, y)).unwrap();
5555
},
5656
_ => {}
5757
}

src/handler.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub async fn handle_key_events(
2222
KeyCode::Char('q') => {
2323
app.quit();
2424
}
25-
KeyCode::Char('c') | KeyCode::Char('C') => {
25+
KeyCode::Char('c' | 'C') => {
2626
if key_event.modifiers == KeyModifiers::CONTROL {
2727
app.quit();
2828
}
@@ -113,7 +113,7 @@ pub async fn handle_key_events(
113113
KeyCode::Char('q') => {
114114
app.quit();
115115
}
116-
KeyCode::Char('c') | KeyCode::Char('C') => {
116+
KeyCode::Char('c' | 'C') => {
117117
if key_event.modifiers == KeyModifiers::CONTROL {
118118
app.quit();
119119
}
@@ -150,7 +150,7 @@ pub async fn handle_key_events(
150150
.as_mut()
151151
.unwrap()
152152
.scan(sender)
153-
.await?
153+
.await?;
154154
}
155155
Mode::Ap => {
156156
app.adapter
@@ -159,10 +159,10 @@ pub async fn handle_key_events(
159159
.as_mut()
160160
.unwrap()
161161
.scan(sender)
162-
.await?
162+
.await?;
163163
}
164164
_ => {}
165-
};
165+
}
166166
}
167167

168168
KeyCode::Tab => match app.adapter.device.mode {
@@ -201,12 +201,12 @@ pub async fn handle_key_events(
201201
if let Some(ap) = &mut app.adapter.device.access_point {
202202
match ap.focused_section {
203203
APFocusedSection::SSID => {
204-
ap.focused_section = APFocusedSection::PSK
204+
ap.focused_section = APFocusedSection::PSK;
205205
}
206206
APFocusedSection::PSK => {
207-
ap.focused_section = APFocusedSection::SSID
207+
ap.focused_section = APFocusedSection::SSID;
208208
}
209-
};
209+
}
210210
}
211211
}
212212
_ => {}
@@ -250,12 +250,12 @@ pub async fn handle_key_events(
250250
if let Some(ap) = &mut app.adapter.device.access_point {
251251
match ap.focused_section {
252252
APFocusedSection::SSID => {
253-
ap.focused_section = APFocusedSection::PSK
253+
ap.focused_section = APFocusedSection::PSK;
254254
}
255255
APFocusedSection::PSK => {
256-
ap.focused_section = APFocusedSection::SSID
256+
ap.focused_section = APFocusedSection::SSID;
257257
}
258-
};
258+
}
259259
}
260260
}
261261
_ => {}
@@ -278,14 +278,14 @@ pub async fn handle_key_events(
278278
Notification::send(
279279
"Device Powered Off".to_string(),
280280
crate::notification::NotificationLevel::Info,
281-
sender.clone(),
281+
&sender.clone(),
282282
)?;
283283
}
284284
Err(e) => {
285285
Notification::send(
286286
e.to_string(),
287287
crate::notification::NotificationLevel::Error,
288-
sender.clone(),
288+
&sender.clone(),
289289
)?;
290290
}
291291
}
@@ -296,14 +296,14 @@ pub async fn handle_key_events(
296296
Notification::send(
297297
"Device Powered On".to_string(),
298298
crate::notification::NotificationLevel::Info,
299-
sender.clone(),
299+
&sender.clone(),
300300
)?;
301301
}
302302
Err(e) => {
303303
Notification::send(
304304
e.to_string(),
305305
crate::notification::NotificationLevel::Error,
306-
sender.clone(),
306+
&sender.clone(),
307307
)?;
308308
}
309309
}

src/help.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Help {
2020
}
2121

2222
impl Help {
23-
pub fn new(config: Arc<Config>) -> Self {
23+
pub fn new(config: &Arc<Config>) -> Self {
2424
let mut state = TableState::new().with_offset(0);
2525
state.select(Some(0));
2626

@@ -159,7 +159,7 @@ impl Help {
159159
.keys
160160
.iter()
161161
.map(|key| {
162-
Row::new(vec![key.0.to_owned(), key.1.into()]).style(match color_mode {
162+
Row::new(vec![key.0.clone(), key.1.into()]).style(match color_mode {
163163
ColorMode::Dark => Style::default().fg(Color::White),
164164
ColorMode::Light => Style::default().fg(Color::Black),
165165
})

src/known_network.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,43 +42,43 @@ impl KnownNetwork {
4242

4343
pub async fn forget(&self, sender: UnboundedSender<Event>) -> AppResult<()> {
4444
if let Err(e) = self.n.forget().await {
45-
Notification::send(e.to_string(), NotificationLevel::Error, sender.clone())?;
45+
Notification::send(e.to_string(), NotificationLevel::Error, &sender.clone())?;
4646
return Ok(());
4747
}
4848

4949
Notification::send(
5050
"Network Removed".to_string(),
5151
NotificationLevel::Info,
52-
sender,
52+
&sender,
5353
)?;
5454
Ok(())
5555
}
5656

5757
pub async fn toggle_autoconnect(&self, sender: UnboundedSender<Event>) -> AppResult<()> {
5858
if self.is_autoconnect {
5959
match self.n.set_autoconnect(false).await {
60-
Ok(_) => {
60+
Ok(()) => {
6161
Notification::send(
6262
format!("Disable Autoconnect for: {}", self.name),
6363
NotificationLevel::Info,
64-
sender.clone(),
64+
&sender.clone(),
6565
)?;
6666
}
6767
Err(e) => {
68-
Notification::send(e.to_string(), NotificationLevel::Error, sender.clone())?;
68+
Notification::send(e.to_string(), NotificationLevel::Error, &sender.clone())?;
6969
}
7070
}
7171
} else {
7272
match self.n.set_autoconnect(true).await {
73-
Ok(_) => {
73+
Ok(()) => {
7474
Notification::send(
7575
format!("Enable Autoconnect for: {}", self.name),
7676
NotificationLevel::Info,
77-
sender.clone(),
77+
&sender.clone(),
7878
)?;
7979
}
8080
Err(e) => {
81-
Notification::send(e.to_string(), NotificationLevel::Error, sender.clone())?;
81+
Notification::send(e.to_string(), NotificationLevel::Error, &sender.clone())?;
8282
}
8383
}
8484
}

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async fn main() -> AppResult<()> {
1919

2020
let config = Arc::new(Config::new());
2121

22-
let help = Help::new(config.clone());
22+
let help = Help::new(&config.clone());
2323

2424
let backend = CrosstermBackend::new(io::stdout());
2525
let terminal = Terminal::new(backend)?;
@@ -52,7 +52,7 @@ async fn main() -> AppResult<()> {
5252
tui.events.sender.clone(),
5353
config.clone(),
5454
)
55-
.await?
55+
.await?;
5656
}
5757
Event::Notification(notification) => {
5858
app.notifications.push(notification);

src/network.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ impl Network {
4343

4444
pub async fn connect(&self, sender: UnboundedSender<Event>) -> AppResult<()> {
4545
match self.n.connect().await {
46-
Ok(_) => Notification::send(
46+
Ok(()) => Notification::send(
4747
format!("Connected to {}", self.name),
4848
NotificationLevel::Info,
49-
sender,
49+
&sender,
5050
)?,
5151
Err(e) => {
5252
if e.to_string().contains("net.connman.iwd.Aborted") {
5353
Notification::send(
5454
"Connection canceled".to_string(),
5555
NotificationLevel::Info,
56-
sender,
57-
)?
56+
&sender,
57+
)?;
5858
} else {
59-
Notification::send(e.to_string(), NotificationLevel::Error, sender)?
59+
Notification::send(e.to_string(), NotificationLevel::Error, &sender)?;
6060
}
6161
}
6262
}

0 commit comments

Comments
 (0)