From 6d55f0ff92e009837862e504d5ec9ced06575061 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sat, 28 Jan 2023 07:53:01 +0100 Subject: [PATCH] refactor --- src/config.rs | 4 ++-- src/pages/index.rs | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index c37a711..b22d422 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,10 +17,10 @@ fn read_json_file(f: &str) -> Option { } impl Config { - pub fn new() -> Config { + pub fn new() -> Self { let v = read_json_file("./config/config.json").expect("could not read config file"); let c = read_json_file("./config/colors.json"); - Config { root: v, color: c } + Self { root: v, color: c } } pub fn name(&self) -> Option { diff --git a/src/pages/index.rs b/src/pages/index.rs index 09df63b..e442f59 100644 --- a/src/pages/index.rs +++ b/src/pages/index.rs @@ -132,7 +132,7 @@ fn build_information_block(conf: &web::Data) -> String { } fn build_contact_block(conf: &web::Data) -> String { - if let Some(email) = conf.email() { + conf.email().map_or_else(String::new, |email| { let pgp_key_message = if std::path::Path::new("./config/pub.key").exists() { html! { a href="/public_key" { "My PGP Key" }; @@ -158,13 +158,11 @@ fn build_contact_block(conf: &web::Data) -> String { } } .into_string() - } else { - String::new() - } + }) } fn build_donation_block(conf: &web::Data) -> String { - if let Some(xmr_addr) = conf.xmr_address() { + conf.xmr_address().map_or_else(String::new, |xmr_addr| { html! { div class="container" style="margin-top: 20px" { h1 { @@ -179,9 +177,7 @@ fn build_donation_block(conf: &web::Data) -> String { } } .into_string() - } else { - String::new() - } + }) } #[get("/")]