From 518c108c3a580fa0dbaaec1c03c7fc7744240297 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Sun, 1 Jan 2023 01:24:41 -0800 Subject: [PATCH 1/1] Appease clippy more --- src/main.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2e5de54..ef09e31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,7 +40,7 @@ fn get_voter(request: &cgi::Request) -> Result<&[u8], cgi::Response> { 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"))?; @@ -83,9 +83,8 @@ fn valid_id_char(c: &u8) -> bool { 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() } } @@ -193,8 +192,7 @@ const HTML_FOOTER: &str = " fn supports(tally: &HashMap>, 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 { @@ -213,11 +211,8 @@ fn prompt_for_vote(dir: PathBuf, request: cgi::Request) -> Result