From 203f4e12d5ad17a5712edb174f239fc82f930b23 Mon Sep 17 00:00:00 2001 From: Gonne Date: Sun, 3 Nov 2024 09:59:05 +0100 Subject: [PATCH] clippy suggestions --- src/main.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index b2242bd..42d55f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,30 +2,29 @@ use std::io::{self}; use std::collections::BTreeMap; fn main() { - let redirects = parse_alias_to_BTreeMap(); + let redirects = parse_alias_to_map(); let sieve_script = generate_sieve_script(redirects); println!("{}", sieve_script); } fn generate_sieve_script(redirects: BTreeMap>) -> String { - let mut script : String = "require [\"envelope\", \"copy\"];\n".to_string(); + let mut script : String = "require [\"envelope\", \"copy\"];\n\n".to_string(); for (redirect, mut destinations) in redirects { script += format!("if envelope :is \"to\" \"{}\" {{\n{}}}\n", redirect, - (|| { + { let mut subscript : String = "".to_string(); destinations.sort(); for destination in destinations.iter().rev().skip(1).rev() { subscript += format!(" redirect :copy \"{}\";\n", destination).as_str(); } - subscript += format!(" redirect \"{}\";\n", destinations.iter().rev().next().unwrap()).as_str(); - return subscript; - })() + subscript + format!(" redirect \"{}\";\n", destinations.iter().next_back().unwrap()).as_str() + } ).as_str(); } - return script; + script } -fn parse_alias_to_BTreeMap() -> BTreeMap> { +fn parse_alias_to_map() -> BTreeMap> { // File must exist in the current path let mut redirect_map : BTreeMap> = BTreeMap::new(); let mut destinations : Vec = Vec::new(); @@ -33,12 +32,12 @@ fn parse_alias_to_BTreeMap() -> BTreeMap> { let line = line.unwrap(); let line = String::from(line.split_at(line.find("#").unwrap_or(line.len())).0); let destination = line.split_at(line.find(char::is_whitespace).unwrap_or(0)).0; - if destination == "" { + if destination.is_empty() { continue; } let redirects: Vec = line.split_at(line.find(char::is_whitespace).unwrap_or(0)).1.split(" ") - .filter(|address| address.trim().to_string().replace(",","") != "").map(|address| to_mailaddress(address)).collect(); - if redirects.len() == 0 { + .filter(|address| address.trim().to_string().replace(",","") != "").map(to_mailaddress).collect(); + if redirects.is_empty() { continue; } destinations.push(to_mailaddress(destination)); @@ -54,7 +53,7 @@ fn parse_alias_to_BTreeMap() -> BTreeMap> { changed = true; all_new_redirects.entry(destination.clone()).or_insert(redirect_map.get(destination).unwrap().clone()) .retain(|dest| *dest != *forward_to); - all_new_redirects.entry(destination.clone()).and_modify(|d| d.extend(new_redirects.iter().map(|x| x.clone()))); + all_new_redirects.entry(destination.clone()).and_modify(|d| d.extend(new_redirects.iter().cloned())); } } } @@ -62,7 +61,7 @@ fn parse_alias_to_BTreeMap() -> BTreeMap> { *redirect_map.get_mut(&destination).unwrap() = new_redirect; } } - return redirect_map; + redirect_map } fn to_mailaddress(local_part: &str) -> String { @@ -71,5 +70,5 @@ fn to_mailaddress(local_part: &str) -> String { if addr.contains("@") { return addr; } - return addr + "@mathebau.de"; + addr + "@mathebau.de" }