Clippy code cleanup

This commit is contained in:
2026-08-15 13:22:59 +03:00
parent 9917702c4c
commit e676898135
22 changed files with 290 additions and 171 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ pub fn add_set(set: &mut CardSetSettings, connection: &Connection) {
pub fn update_card_set(set: &mut CardSetSettings, connection: &Connection) {
if set.id == 0 {
add_set(set, &connection);
add_set(set, connection);
} else {
connection
.execute(
+7 -10
View File
@@ -27,16 +27,16 @@ pub fn load_stats_of_set(set: &CardSetSettings, connection: &Connection) -> Vec<
buffer
}
pub fn add_stat_list(stat: &mut Vec<CardStatistics>, connection: &Connection) {
pub fn add_stat_list(stat: &mut [CardStatistics], connection: &Connection) {
let inserting = stat
.iter()
.map(|stat| {
format!(
"({}, {}, {}, {})",
stat.word_id.to_string(),
stat.set_id.to_string(),
stat.score.to_string(),
stat.last_open.timestamp().to_string()
stat.word_id,
stat.set_id,
stat.score,
stat.last_open.timestamp()
)
})
.collect::<Vec<_>>()
@@ -48,7 +48,6 @@ pub fn add_stat_list(stat: &mut Vec<CardStatistics>, connection: &Connection) {
let count = connection.execute(query.as_str(), ());
if count.is_err() {
println!("{}", count.unwrap_err());
return;
}
@@ -60,12 +59,10 @@ pub fn add_stat_list(stat: &mut Vec<CardStatistics>, connection: &Connection) {
)
.unwrap();
let start_index = last_index - (count.unwrap() as u32) + 1;
let start_index = last_index - (stat.len() as u32) + 1;
let mut index = 0;
for id in start_index..=last_index {
for (index, id) in (start_index..=last_index).enumerate() {
stat[index].id = id;
index += 1;
}
}
+1 -1
View File
@@ -70,7 +70,7 @@ pub fn push_note(set_id: u32, item: HistoryItem) {
item.before,
item.after
);
writeln!(&mut file, "{}", line_str.to_string()).unwrap();
writeln!(&mut file, "{}", line_str).unwrap();
}
pub fn history_dir() -> PathBuf {
+5 -6
View File
@@ -4,14 +4,13 @@ pub fn get_setting(key: String, connection: &Connection) -> Option<String> {
let mut stmt = connection
.prepare("SELECT value FROM settings WHERE id = ?1")
.unwrap();
let iter = stmt.query_map((key,), |row| row.get(0)).unwrap();
let mut iter = stmt.query_map((key,), |row| row.get(0)).unwrap();
for row in iter {
if let Ok(value) = row {
return Some(value);
}
return None;
if let Some(row) = iter.next() && let Ok(value) = row
{
return Some(value);
}
None
}
+3 -4
View File
@@ -24,8 +24,7 @@ pub async fn send_data(id: String) {
fn compress(data: Vec<u8>) -> Vec<u8> {
let mut encoder = Encoder::new(Vec::new(), DEFAULT_COMPRESSION_LEVEL).unwrap();
io::copy(&mut &data[..], &mut encoder).unwrap();
let compressed = encoder.finish().unwrap();
compressed
encoder.finish().unwrap()
}
pub async fn load_data(id: String, temp: bool) {
@@ -84,7 +83,7 @@ pub async fn get_web_version(key: &str) -> Result<u32, reqwest::Error> {
let id_url = format!("{API_URL}{key}/version");
let client = reqwest::Client::new();
let version = client.get(&id_url).send().await?.text().await?;
return Ok(version.parse::<u32>().unwrap());
Ok(version.parse::<u32>().unwrap())
}
pub async fn get_local_version() -> u32 {
@@ -95,7 +94,7 @@ pub async fn get_local_version() -> u32 {
return data.parse::<u32>().unwrap();
}
let mut file = OpenOptions::new().write(true).create(true).open(file).await.unwrap();
let mut file = OpenOptions::new().write(true).create(true).truncate(true).open(file).await.unwrap();
file.write_all("0".as_bytes()).await.unwrap();
0
}
+3 -5
View File
@@ -50,16 +50,14 @@ pub fn add_words(words: &mut[WordData], connection: &mut Connection) {
let start_index = last_index - (count as u32) + 1;
let mut index = 0;
for id in start_index..=last_index {
for (index, id) in (start_index..=last_index).enumerate() {
words[index].id = id;
index += 1;
}
}
pub fn update_word(word: &mut WordData, connection: &Connection) {
if word.id == 0 {
add_word(word, &connection);
add_word(word, connection);
} else {
connection
.execute(
@@ -155,7 +153,7 @@ pub fn add_group(group: &mut WordGroup, connection: &Connection) {
pub fn update_group(group: &mut WordGroup, connection: &Connection) {
if group.id == 0 {
add_group(group, &connection);
add_group(group, connection);
} else {
connection
.execute(