From 5a06631e056aaf1870f7b69e1f8f7623aa3b82f4 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Fri, 12 Jun 2020 00:07:42 +0200 Subject: [PATCH] Cleanup the code --- acmed/src/endpoint.rs | 2 +- acmed/src/http.rs | 2 +- acmed/src/main_event_loop.rs | 7 +++---- acmed/src/storage.rs | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/acmed/src/endpoint.rs b/acmed/src/endpoint.rs index ce7bc4a..89e5ea6 100644 --- a/acmed/src/endpoint.rs +++ b/acmed/src/endpoint.rs @@ -130,7 +130,7 @@ fn is_duration_chr(c: char) -> bool { fn get_multiplicator(input: &str) -> IResult<&str, u64> { let (input, nb) = take_while_m_n(1, 1, is_duration_chr)(input)?; - let mult = match nb.chars().nth(0) { + let mult = match nb.chars().next() { Some('s') => 1, Some('m') => 60, Some('h') => 3_600, diff --git a/acmed/src/http.rs b/acmed/src/http.rs index 7bdcbff..ccedc98 100644 --- a/acmed/src/http.rs +++ b/acmed/src/http.rs @@ -34,7 +34,7 @@ fn update_nonce(endpoint: &mut Endpoint, response: &Response) -> Result<(), Erro let msg = format!("{}: invalid nonce.", &nonce); return Err(msg.into()); } - endpoint.nonce = Some(nonce.to_string()); + endpoint.nonce = Some(nonce); } Ok(()) } diff --git a/acmed/src/main_event_loop.rs b/acmed/src/main_event_loop.rs index 5dbd743..b4ddb00 100644 --- a/acmed/src/main_event_loop.rs +++ b/acmed/src/main_event_loop.rs @@ -64,10 +64,9 @@ impl MainEventLoop { env: crt.env.to_owned(), id: i + 1, }; - if !endpoints.contains_key(&endpoint_name) { - let ep = Arc::new(RwLock::new(endpoint)); - endpoints.insert(endpoint_name, ep); - } + endpoints + .entry(endpoint_name) + .or_insert_with(|| Arc::new(RwLock::new(endpoint))); init_account(&cert)?; certs.push(cert); } diff --git a/acmed/src/storage.rs b/acmed/src/storage.rs index 6acad59..2d6b728 100644 --- a/acmed/src/storage.rs +++ b/acmed/src/storage.rs @@ -135,7 +135,7 @@ fn write_file(cert: &Certificate, file_type: FileType, data: &[u8]) -> Result<() let mut hook_data = FileStorageHookData { file_name, file_directory, - file_path: path.to_path_buf(), + file_path: path.to_owned(), env: HashMap::new(), }; hook_data.set_env(&cert.env);