Skip to content

Commit 4c2fe54

Browse files
committed
style: fix clippy hints
1 parent 4694c97 commit 4c2fe54

File tree

10 files changed

+38
-38
lines changed

10 files changed

+38
-38
lines changed

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ use crate::subsystems::volume_control::VolumeControl;
1818

1919
mod nfc;
2020
mod subsystems;
21-
mod wpa_supplicant;
21+
mod wifi;
2222

2323
#[tokio::main]
2424
async fn main() -> Result<()> {
2525
Builder::from_env(Env::default().default_filter_or("debug")).init();
2626

27-
let home_dir = dirs::home_dir().ok_or(anyhow!("Home directory not found"))?;
27+
let home_dir = dirs::home_dir().ok_or_else(|| anyhow!("Home directory not found"))?;
2828
let local_dir = Path::new(&home_dir).join(".boop-box");
2929
let cache_dir = Path::new(&local_dir).join("cache");
3030

src/nfc/ndef.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl NdefMessageParser {
3131
}
3232
}
3333

34-
pub fn add_data(&mut self, data: &[u8]) -> () {
34+
pub fn add_data(&mut self, data: &[u8]) {
3535
for byte in data {
3636
match self.state {
3737
NdefMessageParserState::Init => {
@@ -65,16 +65,14 @@ impl NdefMessageParser {
6565
}
6666

6767
NdefMessageParserState::Value => {
68-
self.data.push(byte.clone());
68+
self.data.push(*byte);
6969

7070
if self.data.len() as i32 == self.length {
71-
return ();
71+
return;
7272
}
7373
}
7474
}
7575
}
76-
77-
()
7876
}
7977

8078
pub fn is_done(&self) -> bool {
@@ -93,7 +91,7 @@ pub struct NdefTextRecord {
9391

9492
impl NdefTextRecord {
9593
pub fn text(&self) -> Result<String> {
96-
if self.value.len() == 0 {
94+
if self.value.is_empty() {
9795
return Ok(String::new());
9896
}
9997

@@ -169,7 +167,7 @@ pub fn parse_ndef_text_record(data: &Vec<u8>) -> Result<NdefTextRecord> {
169167
let type_index = index;
170168
index += type_length as usize;
171169

172-
if record_length <= type_index + type_length as usize - 1 {
170+
if record_length < type_index + type_length as usize {
173171
return Err(anyhow!("Type missing"));
174172
}
175173

@@ -182,7 +180,7 @@ pub fn parse_ndef_text_record(data: &Vec<u8>) -> Result<NdefTextRecord> {
182180
let id_index = index;
183181
index += id_length as usize;
184182

185-
if record_length <= id_index + id_length as usize - 1 {
183+
if record_length < id_index + id_length as usize {
186184
return Err(anyhow!("ID missing"));
187185
}
188186

@@ -194,7 +192,7 @@ pub fn parse_ndef_text_record(data: &Vec<u8>) -> Result<NdefTextRecord> {
194192
let payload_value = if payload_length > 0 {
195193
let value_index = index;
196194

197-
if record_length <= value_index + payload_length as usize - 1 {
195+
if record_length < value_index + payload_length as usize {
198196
return Err(anyhow!("Payload missing"));
199197
}
200198

src/nfc/reader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ impl<'a> NfcReader<'a> {
8585
sector * 4 + 3,
8686
auth_option.key_type,
8787
&auth_option.key,
88-
&uid,
88+
uid,
8989
)?;
9090
}
9191
None => {
92-
let auth_option = self.try_authenticate_block(sector * 4 + 3, &uid)?;
92+
let auth_option = self.try_authenticate_block(sector * 4 + 3, uid)?;
9393
maybe_auth_option = Some(auth_option);
9494
}
9595
}
@@ -113,7 +113,7 @@ impl<'a> NfcReader<'a> {
113113
}
114114

115115
let record = parse_ndef_text_record(&ndef_message_parser.data)?;
116-
Ok(record.text()?)
116+
record.text()
117117
}
118118

119119
fn read_block(&mut self, block_number: u8) -> Result<[u8; 16]> {

src/subsystems/audio_player.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl AudioPlayer {
5353
rx: mpsc::Receiver<PlayerCommand>,
5454
) -> Self {
5555
Self {
56-
cache_path: cache_path.to_path_buf(),
56+
cache_path,
5757
boop_paths: Self::collect_paths("boop").expect(""),
5858
confirm_paths: Self::collect_paths("confirm").expect(""),
5959
rx,
@@ -89,7 +89,7 @@ impl AudioPlayer {
8989
PlayAsset { path, done } => {
9090
let file = ASSETS_DIR
9191
.get_file(&path)
92-
.ok_or(anyhow!("Asset file missing: {}", path.display()))
92+
.ok_or_else(|| anyhow!("Asset file missing: {}", path.display()))
9393
.unwrap();
9494
play_wav.load_mem(file.contents()).unwrap();
9595
return Some(PlayState {
@@ -168,7 +168,7 @@ impl AudioPlayer {
168168
let path = self
169169
.boop_paths
170170
.choose(&mut rand::thread_rng())
171-
.ok_or(anyhow!("No boop files available"))?
171+
.ok_or_else(|| anyhow!("No boop files available"))?
172172
.clone();
173173
soloud_tx
174174
.send(SoloudCommand::PlayAsset { path, done })
@@ -178,7 +178,7 @@ impl AudioPlayer {
178178
let path = self
179179
.confirm_paths
180180
.choose(&mut rand::thread_rng())
181-
.ok_or(anyhow!("No confirm files available"))?
181+
.ok_or_else(|| anyhow!("No confirm files available"))?
182182
.clone();
183183
soloud_tx
184184
.send(SoloudCommand::PlayAsset { path, done })
@@ -248,7 +248,7 @@ impl AudioPlayer {
248248

249249
for file in ASSETS_DIR
250250
.get_dir(dir_name)
251-
.ok_or(anyhow!("Directory missing: {}", dir_name))?
251+
.ok_or_else(|| anyhow!("Directory missing: {}", dir_name))?
252252
.files()
253253
{
254254
let path = file.path();

src/subsystems/config_manager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl ConfigManager {
7373
Ok(mut file) => {
7474
let mut toml_config = String::new();
7575
file.read_to_string(&mut toml_config).await?;
76-
let config: Config = toml::from_str(&mut toml_config)?;
76+
let config: Config = toml::from_str(&toml_config)?;
7777
config
7878
}
7979
Err(_) => Config {
@@ -97,7 +97,7 @@ impl ConfigManager {
9797
config_uids,
9898
responder,
9999
} => {
100-
(&mut config).config_uids = config_uids;
100+
config.config_uids = config_uids;
101101
self.store_config(&config).await?;
102102
responder.send(()).unwrap();
103103
}
@@ -108,7 +108,7 @@ impl ConfigManager {
108108
volume_config,
109109
responder,
110110
} => {
111-
(&mut config).volume = volume_config;
111+
config.volume = volume_config;
112112
self.store_config(&config).await?;
113113
responder.send(()).unwrap();
114114
}
@@ -119,7 +119,7 @@ impl ConfigManager {
119119
connection_config,
120120
responder,
121121
} => {
122-
(&mut config).connection = Some(connection_config);
122+
config.connection = Some(connection_config);
123123
self.store_config(&config).await?;
124124
responder.send(()).unwrap();
125125
}

src/subsystems/controller.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::{anyhow, Error, Result};
22
use log::info;
3-
use std::path::{Path, PathBuf};
3+
use std::path::PathBuf;
44
use std::time::Duration;
55
use tokio::fs::metadata;
66
use tokio::fs::File;
@@ -16,7 +16,7 @@ use crate::subsystems::audio_player::PlayerCommand;
1616
use crate::subsystems::config_manager::{ConfigCommand, ConnectionConfig};
1717
use crate::subsystems::led::{LedState, BLUE, CYAN, GREEN, MAGENTA, RED, YELLOW};
1818
use crate::subsystems::networker::{NetworkerCommand, NetworkerStatus};
19-
use crate::wpa_supplicant::wpa_supplicant::set_wifi;
19+
use crate::wifi::wpa_supplicant::set_wifi;
2020

2121
pub struct Controller {
2222
cache_path: PathBuf,
@@ -57,7 +57,7 @@ impl Controller {
5757
.await?;
5858
let mut config_uids = config_rx.await?;
5959

60-
if config_uids.len() == 0 {
60+
if config_uids.is_empty() {
6161
self.add_config_uid(&mut config_uids, nfc.clone()).await?;
6262
self.wait_for_release(&nfc).await?;
6363
}
@@ -106,7 +106,7 @@ impl Controller {
106106
if metadata(&path).await.is_err() {
107107
let (response_tx, response_rx) = oneshot::channel();
108108
self.networker.send(NetworkerCommand::GetAudio {
109-
id: achievement_id.clone(),
109+
id: *achievement_id,
110110
responder: response_tx,
111111
}).await?;
112112
let maybe_data = response_rx.await?;
@@ -189,7 +189,7 @@ impl Controller {
189189
}
190190
};
191191

192-
if value.len() < 1 {
192+
if value.is_empty() {
193193
return Err(anyhow!("Value too short"));
194194
}
195195

src/subsystems/led.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub const BLUE: Color = (Level::Low, Level::Low, Level::High);
1313
pub const YELLOW: Color = (Level::High, Level::High, Level::Low);
1414
pub const MAGENTA: Color = (Level::High, Level::Low, Level::High);
1515
pub const CYAN: Color = (Level::Low, Level::High, Level::High);
16-
pub const WHITE: Color = (Level::High, Level::High, Level::High);
1716

1817
#[derive(Debug)]
1918
pub enum LedState {

src/subsystems/networker.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use std::io;
22
use std::net::ToSocketAddrs;
3-
use std::path::{Path, PathBuf};
3+
44
use std::pin::Pin;
55
use std::sync::Arc;
66
use std::time::Duration;
77

8-
use anyhow::{anyhow, bail, ensure, Error, Result};
9-
use futures_util::pin_mut;
8+
use anyhow::{Error, Result};
9+
1010
use log::info;
11-
use serde::{Deserialize, Serialize};
11+
1212
use thiserror;
13-
use tokio::fs::File;
13+
1414
use tokio::io::{AsyncReadExt, AsyncWriteExt};
1515
use tokio::net::TcpStream;
1616
use tokio::sync::mpsc;
@@ -20,7 +20,7 @@ use tokio_graceful_shutdown::{IntoSubsystem, SubsystemHandle};
2020
use tokio_io_timeout::TimeoutStream;
2121
use tokio_rustls::client::TlsStream;
2222
use tokio_rustls::rustls::{self, ClientConfig, OwnedTrustAnchor};
23-
use tokio_rustls::{Connect, TlsConnector};
23+
use tokio_rustls::TlsConnector;
2424

2525
use crate::nfc::reader::Uid;
2626
use crate::subsystems::config_manager::{ConfigCommand, ConnectionConfig};
@@ -170,10 +170,13 @@ impl Networker {
170170
if let Some(connection_config) = maybe_connection_config.as_ref() {
171171
if let Ok(maybe_connected_stream) = self.connect(
172172
&connector,
173-
&connection_config
173+
connection_config
174174
).await {
175175
match maybe_connected_stream {
176-
Some(connected_stream) => maybe_stream = Some(connected_stream),
176+
Some(connected_stream) => {
177+
maybe_stream = Some(connected_stream);
178+
self.status_tx.send(NetworkerStatus::Connected).await?
179+
},
177180
None => {
178181
self.status_tx.send(NetworkerStatus::InvalidCredentials).await?
179182
},
@@ -265,7 +268,7 @@ impl Networker {
265268
let mut pinned_stream = Box::pin(timeout_stream);
266269

267270
if !self
268-
.authenticate(&mut pinned_stream, &connection_config)
271+
.authenticate(&mut pinned_stream, connection_config)
269272
.await?
270273
{
271274
return Ok(None);
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)