Skip to content

Commit 51f39e4

Browse files
committed
Applying clippy fixes to dev-tracker-core.
1 parent 03921cb commit 51f39e4

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

dev-tracker-core/src/data.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ impl DataStore {
102102
let mut projects = Project::get_with_name(name, &self.conn)?;
103103

104104
if projects.len() == 1 {
105-
return Ok(Some(projects.remove(0)));
105+
Ok(Some(projects.remove(0)))
106106
} else {
107-
return Ok(None);
107+
Ok(None)
108108
}
109109
}
110110

@@ -171,9 +171,9 @@ impl DataStore {
171171
let mut ats = ActivityType::get_with_name(name, &self.conn)?;
172172

173173
if ats.len() == 1 {
174-
return Ok(Some(ats.remove(0)));
174+
Ok(Some(ats.remove(0)))
175175
} else {
176-
return Ok(None);
176+
Ok(None)
177177
}
178178
}
179179

@@ -260,9 +260,9 @@ impl DataStore {
260260
.collect();
261261

262262
if activities.len() == 1 {
263-
return Ok(Some(activities.remove(0)));
263+
Ok(Some(activities.remove(0)))
264264
} else {
265-
return Ok(None);
265+
Ok(None)
266266
}
267267
}
268268

@@ -322,9 +322,9 @@ impl DataStore {
322322
let mut repos = Repo::get_with_path(path, &self.conn)?;
323323

324324
if repos.len() == 1 {
325-
return Ok(Some(repos.remove(0)));
325+
Ok(Some(repos.remove(0)))
326326
} else {
327-
return Ok(None);
327+
Ok(None)
328328
}
329329
}
330330

@@ -404,6 +404,7 @@ impl DataStore {
404404

405405
pub fn get_latest_count(&self, repo: &Repo) -> Result<Option<Count>, Error> {
406406
let mut counts = self.get_counts(repo)?;
407+
#[allow(clippy::comparison_chain)]
407408
counts.sort_by(|a, b| {
408409
if a.date < b.date {
409410
Ordering::Less
@@ -414,10 +415,10 @@ impl DataStore {
414415
}
415416
});
416417

417-
if counts.len() > 0 {
418-
return Ok(Some(counts.remove(counts.len() - 1)));
418+
if !counts.is_empty() {
419+
Ok(Some(counts.remove(counts.len() - 1)))
419420
} else {
420-
return Ok(None);
421+
Ok(None)
421422
}
422423
}
423424

dev-tracker-core/src/model/activity.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ impl Activity {
5858
pub fn new(project: u64, atype: u64, description: Option<String>) -> Self {
5959
Self {
6060
id: 0,
61-
project: project,
62-
atype: atype,
61+
project,
62+
atype,
6363
description,
6464
start: Utc::now(),
6565
end: None,
@@ -149,9 +149,9 @@ impl Activity {
149149
.collect();
150150

151151
if activities.len() == 1 {
152-
return Ok(Some(activities.remove(0)));
152+
Ok(Some(activities.remove(0)))
153153
} else {
154-
return Ok(None);
154+
Ok(None)
155155
}
156156
}
157157

@@ -210,7 +210,7 @@ impl Activity {
210210
pub(crate) fn delete(self, conn: &Connection) -> Result<(), Error> {
211211
conn.execute(
212212
"DELETE FROM activities WHERE id=?1",
213-
&[&self.id.to_string()],
213+
[&self.id.to_string()],
214214
)?;
215215
Ok(())
216216
}

dev-tracker-core/src/model/activitytype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ impl ActivityType {
9090
.collect();
9191

9292
if ats.len() == 1 {
93-
return Ok(Some(ats.remove(0)));
93+
Ok(Some(ats.remove(0)))
9494
} else {
95-
return Ok(None);
95+
Ok(None)
9696
}
9797
}
9898

@@ -139,7 +139,7 @@ impl ActivityType {
139139
}
140140

141141
pub(crate) fn delete(self, conn: &Connection) -> Result<(), Error> {
142-
conn.execute("DELETE FROM activitytypes WHERE id=?1", &[&self.id])?;
142+
conn.execute("DELETE FROM activitytypes WHERE id=?1", [&self.id])?;
143143
Ok(())
144144
}
145145
}

dev-tracker-core/src/model/count.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ impl Count {
8787
id: row.get(0)?,
8888
repo: row.get(1)?,
8989
date: row.get(2)?,
90-
count: count,
90+
count,
9191
})
9292
})?
9393
.filter_map(|p| p.ok())
9494
.collect();
9595

9696
if counts.len() == 1 {
97-
return Ok(Some(counts.remove(0)));
97+
Ok(Some(counts.remove(0)))
9898
} else {
99-
return Ok(None);
99+
Ok(None)
100100
}
101101
}
102102

@@ -110,7 +110,7 @@ impl Count {
110110
id: row.get(0)?,
111111
repo: row.get(1)?,
112112
date: row.get(2)?,
113-
count: count,
113+
count,
114114
})
115115
})?
116116
.filter_map(|p| p.ok())
@@ -120,7 +120,7 @@ impl Count {
120120
}
121121

122122
pub(crate) fn delete(self, conn: &Connection) -> Result<(), Error> {
123-
conn.execute("DELETE FROM counts WHERE id=?1", &[&self.id])?;
123+
conn.execute("DELETE FROM counts WHERE id=?1", [&self.id])?;
124124
Ok(())
125125
}
126126
}

dev-tracker-core/src/model/project.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Project {
4747

4848
impl Project {
4949
pub(crate) fn create(&self, conn: &Connection) -> Result<(), Error> {
50-
conn.execute("INSERT INTO projects (name) VALUES (?1)", &[&self.name])?;
50+
conn.execute("INSERT INTO projects (name) VALUES (?1)", [&self.name])?;
5151
Ok(())
5252
}
5353

@@ -64,9 +64,9 @@ impl Project {
6464
.collect();
6565

6666
if projects.len() == 1 {
67-
return Ok(Some(projects.remove(0)));
67+
Ok(Some(projects.remove(0)))
6868
} else {
69-
return Ok(None);
69+
Ok(None)
7070
}
7171
}
7272

@@ -110,7 +110,7 @@ impl Project {
110110
}
111111

112112
pub(crate) fn delete(self, conn: &Connection) -> Result<(), Error> {
113-
conn.execute("DELETE FROM projects WHERE id=?1", &[&self.id])?;
113+
conn.execute("DELETE FROM projects WHERE id=?1", [&self.id])?;
114114
Ok(())
115115
}
116116
}

dev-tracker-core/src/model/repo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ impl Repo {
8686
.collect();
8787

8888
if repos.len() == 1 {
89-
return Ok(Some(repos.remove(0)));
89+
Ok(Some(repos.remove(0)))
9090
} else {
91-
return Ok(None);
91+
Ok(None)
9292
}
9393
}
9494

@@ -136,7 +136,7 @@ impl Repo {
136136
}
137137

138138
pub(crate) fn delete(self, conn: &Connection) -> Result<(), Error> {
139-
conn.execute("DELETE FROM repos WHERE id=?1", &[&self.id])?;
139+
conn.execute("DELETE FROM repos WHERE id=?1", [&self.id])?;
140140
Ok(())
141141
}
142142
}

0 commit comments

Comments
 (0)