Skip to content

Commit eb1cac6

Browse files
committed
backend: fix cargo clippy
1 parent bd3921c commit eb1cac6

File tree

23 files changed

+107
-94
lines changed

23 files changed

+107
-94
lines changed

backend/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub fn clean_chargers(conn: &mut PooledConnection<diesel::r2d2::ConnectionManage
214214
.load(conn)
215215
{
216216
Ok(users) => {
217-
if users.len() == 0 {
217+
if users.is_empty() {
218218
use db_connector::schema::chargers::dsl::*;
219219

220220
let _ = diesel::delete(chargers.find(&charger.id))
@@ -268,7 +268,7 @@ pub(crate) mod tests {
268268
#[macro_export]
269269
macro_rules! defer {
270270
($e:expr) => {
271-
let _scope_call = crate::tests::ScopeCall {
271+
let _scope_call = $crate::tests::ScopeCall {
272272
c: || -> () {
273273
$e;
274274
},
@@ -292,7 +292,7 @@ pub(crate) mod tests {
292292
pub fn create_test_state(
293293
pool: Option<diesel::r2d2::Pool<ConnectionManager<PgConnection>>>,
294294
) -> web::Data<AppState> {
295-
let pool = pool.unwrap_or_else(|| db_connector::test_connection_pool());
295+
let pool = pool.unwrap_or_else(db_connector::test_connection_pool);
296296

297297
let state = AppState {
298298
pool: pool.clone(),
@@ -444,7 +444,7 @@ pub(crate) mod tests {
444444
#[actix_web::test]
445445
async fn test_clean_verification_tokens() {
446446
let user_id = uuid::Uuid::new_v4();
447-
let email = format!("{}@invalid", user_id.to_string());
447+
let email = format!("{}@invalid", user_id);
448448
let user = User {
449449
id: user_id,
450450
name: user_id.to_string(),
@@ -464,7 +464,7 @@ pub(crate) mod tests {
464464
let user2 = User {
465465
id: user2_id,
466466
name: user2_id.to_string(),
467-
email: format!("{}@invalid", user2_id.to_string()),
467+
email: format!("{}@invalid", user2_id),
468468
login_key: String::new(),
469469
email_verified: false,
470470
secret: Vec::new(),
@@ -480,7 +480,7 @@ pub(crate) mod tests {
480480
let user3 = User {
481481
id: user3_id,
482482
name: user3_id.to_string(),
483-
email: format!("{}@invalid", user3_id.to_string()),
483+
email: format!("{}@invalid", user3_id),
484484
login_key: String::new(),
485485
email_verified: true,
486486
secret: Vec::new(),
@@ -496,7 +496,7 @@ pub(crate) mod tests {
496496
let user4 = User {
497497
id: user4_id,
498498
name: user4_id.to_string(),
499-
email: format!("{}@invalid", user4_id.to_string()),
499+
email: format!("{}@invalid", user4_id),
500500
login_key: String::new(),
501501
email_verified: false,
502502
secret: Vec::new(),
@@ -611,8 +611,8 @@ pub(crate) mod tests {
611611
assert!(u.iter().any(|u| u.id == user3_id));
612612
assert!(u.iter().any(|u| u.id == user4_id));
613613

614-
let user = u.into_iter().find(|u| u.id == user4_id).unwrap();
615-
user
614+
615+
u.into_iter().find(|u| u.id == user4_id).unwrap()
616616
};
617617

618618
assert_eq!(user.email, email);

backend/src/middleware/jwt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ where
8686
}
8787

8888
let fut = self.service.call(req);
89-
Box::pin(async move { fut.await })
89+
Box::pin(fut)
9090
}
9191
}
9292

backend/src/monitoring.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ fn send_mail(state: &web::Data<AppState>, num_users: i64, num_chargers: i64) ->
5050
}
5151

5252
pub fn start_monitoring(state: web::Data<AppState>) {
53-
if let Err(_) = std::env::var("SERVER_NAME") {
53+
if std::env::var("SERVER_NAME").is_err() {
5454
log::info!("Monitoring Mailer disabled");
5555
return;
5656
}
57-
if let Err(_) = std::env::var("MONITORING_EMAIL") {
57+
if std::env::var("MONITORING_EMAIL").is_err() {
5858
log::info!("Monitoring Mailer disabled");
5959
return;
6060
}

backend/src/rate_limit.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ pub struct LoginRateLimiter(
6565
>,
6666
);
6767

68+
impl Default for LoginRateLimiter {
69+
fn default() -> Self {
70+
Self::new()
71+
}
72+
}
73+
6874
impl LoginRateLimiter {
6975
pub fn new() -> Self {
7076
Self(RateLimiter::keyed(
@@ -104,6 +110,12 @@ pub struct ChargerRateLimiter(
104110
>,
105111
);
106112

113+
impl Default for ChargerRateLimiter {
114+
fn default() -> Self {
115+
Self::new()
116+
}
117+
}
118+
107119
impl ChargerRateLimiter {
108120
pub fn new() -> Self {
109121
Self(RateLimiter::keyed(
@@ -169,6 +181,12 @@ pub struct IPRateLimiter(
169181
>,
170182
);
171183

184+
impl Default for IPRateLimiter {
185+
fn default() -> Self {
186+
Self::new()
187+
}
188+
}
189+
172190
impl IPRateLimiter {
173191
pub fn new() -> Self {
174192
Self(RateLimiter::keyed(

backend/src/routes/auth/get_login_salt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub async fn get_login_salt(
5454
Err(NotFound) => Ok(cache
5555
.lock()
5656
.unwrap()
57-
.get_or_insert(mail, || generate_random_bytes())
57+
.get_or_insert(mail, generate_random_bytes)
5858
.to_vec()),
5959
Err(_err) => Err(Error::InternalError),
6060
}
@@ -126,7 +126,7 @@ pub mod tests {
126126
let app = App::new().configure(configure).service(get_login_salt);
127127
let app = test::init_service(app).await;
128128

129-
let mail = format!("{}@example.invalid", uuid::Uuid::new_v4().to_string());
129+
let mail = format!("{}@example.invalid", uuid::Uuid::new_v4());
130130

131131
let req = test::TestRequest::get()
132132
.uri(&format!("/get_login_salt?email={}", mail))
@@ -147,7 +147,7 @@ pub mod tests {
147147
let second_salt: Vec<u8> = test::read_body_json(resp).await;
148148
assert_eq!(second_salt, first_salt);
149149

150-
let mail = format!("{}@example.invalid", uuid::Uuid::new_v4().to_string());
150+
let mail = format!("{}@example.invalid", uuid::Uuid::new_v4());
151151
let req = test::TestRequest::get()
152152
.uri(&format!("/get_login_salt?email={}", mail))
153153
.append_header(("X-Forwarded-For", "123.123.123.2"))

backend/src/routes/auth/jwt_refresh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub async fn jwt_refresh(
173173
.secure(true)
174174
.finish();
175175

176-
let cookie_string = format!("{}; Partitioned;", cookie.to_string());
176+
let cookie_string = format!("{}; Partitioned;", cookie);
177177

178178
let refresh_cookie = create_refresh_token(&state, user.id).await?;
179179

backend/src/routes/auth/login.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub async fn login(
160160
.secure(true)
161161
.finish();
162162

163-
let cookie_string = format!("{}; Partitioned;", cookie.to_string());
163+
let cookie_string = format!("{}; Partitioned;", cookie);
164164
let refresh_cookie = create_refresh_token(&state, uuid).await?;
165165

166166
Ok(HttpResponse::Ok()
@@ -226,7 +226,7 @@ pub async fn create_refresh_token(
226226
.secure(true)
227227
.finish();
228228

229-
Ok(format!("{}; Partitioned;", cookie.to_string()))
229+
Ok(format!("{}; Partitioned;", cookie))
230230
}
231231

232232
#[cfg(test)]

backend/src/routes/auth/recovery.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ async fn get_user_id(state: &web::Data<AppState>, recovery_key: Uuid) -> actix_w
5353

5454
match diesel::delete(recovery_tokens.find(recovery_key)).execute(&mut conn) {
5555
Ok(_) => Ok(()),
56-
Err(_err) => return Err(Error::InternalError),
56+
Err(_err) => Err(Error::InternalError),
5757
}
5858
})
5959
.await?;
@@ -123,7 +123,7 @@ pub async fn recovery(
123123

124124
let new_hash = match hash_key(&data.new_login_key) {
125125
Ok(hash) => hash,
126-
Err(_err) => return Err(Error::InternalError.into()),
126+
Err(_err) => return Err(Error::InternalError),
127127
};
128128

129129
match diesel::update(users.find(user_id))

backend/src/routes/auth/register.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn send_verification_mail(
9292
let link = format!(
9393
"{}/api/auth/verify?id={}",
9494
state.frontend_url,
95-
id.id.to_string()
95+
id.id
9696
);
9797

9898
let (body, subject) = match lang.as_str() {
@@ -201,7 +201,7 @@ pub async fn register(
201201

202202
let verify = Verification {
203203
id: uuid::Uuid::new_v4(),
204-
user: user_insert.id.clone(),
204+
user: user_insert.id,
205205
expiration: exp,
206206
};
207207

@@ -378,7 +378,7 @@ pub(crate) mod tests {
378378
let resp = test::call_service(&app, req).await;
379379

380380
assert!(resp.status().is_client_error());
381-
assert_eq!(false, user_exists(mail));
381+
assert!(!user_exists(mail));
382382
}
383383

384384
#[actix_web::test]
@@ -405,7 +405,7 @@ pub(crate) mod tests {
405405
let resp = test::call_service(&app, req).await;
406406

407407
assert!(resp.status().is_client_error());
408-
assert_eq!(false, user_exists(mail));
408+
assert!(!user_exists(mail));
409409
}
410410

411411
#[actix_web::test]
@@ -432,7 +432,7 @@ pub(crate) mod tests {
432432
println!("{}", resp.status());
433433

434434
assert!(resp.status().is_success());
435-
assert_eq!(true, user_exists(mail));
435+
assert!(user_exists(mail));
436436
delete_user("[email protected]");
437437
}
438438

backend/src/routes/auth/start_recovery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub mod tests {
167167
let resp = test::call_service(&app, req).await;
168168
assert_eq!(resp.status(), 200);
169169

170-
let uid = get_test_uuid(&mail).unwrap();
170+
let uid = get_test_uuid(mail).unwrap();
171171
let pool = test_connection_pool();
172172
let mut conn = pool.get().unwrap();
173173
let token: RecoveryToken = recovery_tokens

0 commit comments

Comments
 (0)