]> git.scottworley.com Git - voter/commitdiff
Appease clippy more
authorScott Worley <scottworley@scottworley.com>
Sun, 1 Jan 2023 09:24:41 +0000 (01:24 -0800)
committerScott Worley <scottworley@scottworley.com>
Sun, 1 Jan 2023 09:37:15 +0000 (01:37 -0800)
src/main.rs

index 2e5de542f4381e15ecf3646bb45f6348f6aea5e2..ef09e3138a5985dc8db36aebc7a9170d57877fbf 100644 (file)
@@ -40,7 +40,7 @@ fn get_voter(request: &cgi::Request) -> Result<&[u8], cgi::Response> {
     let cookie = request
         .headers()
         .get(cgi::http::header::COOKIE)
     let cookie = request
         .headers()
         .get(cgi::http::header::COOKIE)
-        .map(|c| c.as_bytes())
+        .map(cgi::http::HeaderValue::as_bytes)
         .and_then(|c| c.strip_prefix(COOKIE_NAME))
         .and_then(|c| c.strip_prefix(b"="))
         .ok_or_else(|| cgi::text_response(400, "Invalid cookie"))?;
         .and_then(|c| c.strip_prefix(COOKIE_NAME))
         .and_then(|c| c.strip_prefix(b"="))
         .ok_or_else(|| cgi::text_response(400, "Invalid cookie"))?;
@@ -83,9 +83,8 @@ fn valid_id_char(c: &u8) -> bool {
 
 fn make_random_id() -> [u8; COOKIE_LENGTH] {
     let mut id = [0; COOKIE_LENGTH];
 
 fn make_random_id() -> [u8; COOKIE_LENGTH] {
     let mut id = [0; COOKIE_LENGTH];
-    for c in id.iter_mut() {
-        while !valid_id_char(c)
-        {
+    for c in &mut id {
+        while !valid_id_char(c) {
             *c = random()
         }
     }
             *c = random()
         }
     }
@@ -193,8 +192,7 @@ const HTML_FOOTER: &str = "
 fn supports(tally: &HashMap<String, HashSet<String>>, me: &str, candidate: &str) -> bool {
     tally
         .get(candidate)
 fn supports(tally: &HashMap<String, HashSet<String>>, me: &str, candidate: &str) -> bool {
     tally
         .get(candidate)
-        .map(|supporters| supporters.contains(me))
-        .unwrap_or(false)
+        .map_or(false, |supporters| supporters.contains(me))
 }
 
 fn prompt_for_vote(dir: PathBuf, request: cgi::Request) -> Result<cgi::Response, cgi::Response> {
 }
 
 fn prompt_for_vote(dir: PathBuf, request: cgi::Request) -> Result<cgi::Response, cgi::Response> {
@@ -213,11 +211,8 @@ fn prompt_for_vote(dir: PathBuf, request: cgi::Request) -> Result<cgi::Response,
         std::iter::once(Ok(HTML_HEADER.to_owned()))
             .chain(std::io::BufReader::new(cfile).lines().map(|rc| {
                 rc.map(|c| {
         std::iter::once(Ok(HTML_HEADER.to_owned()))
             .chain(std::io::BufReader::new(cfile).lines().map(|rc| {
                 rc.map(|c| {
-                    let count = tally
-                        .get(&c)
-                        .map(|supporters| supporters.len())
-                        .unwrap_or(0);
-                    let checked = if me.map(|me| supports(&tally, me, &c)).unwrap_or(false) {
+                    let count = tally.get(&c).map_or(0, std::collections::HashSet::len);
+                    let checked = if me.map_or(false, |me| supports(&tally, me, &c)) {
                         "checked"
                     } else {
                         ""
                         "checked"
                     } else {
                         ""