From 6b932d45ba3fb3e150474f9cefeecad7f66acdf3 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 9 Feb 2023 11:42:33 +0100 Subject: [PATCH] use default trait --- src/config.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index 3ec3a16..be1a23f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,7 @@ use serde::Deserialize; +use std::fs; -#[derive(Deserialize, Clone)] +#[derive(Deserialize, Clone, Default)] pub struct Config { pub scheme: Option, pub port: Option, @@ -9,7 +10,7 @@ pub struct Config { } pub fn get_config(file_path: &str) -> Config { - match std::fs::read_to_string(file_path) { + match fs::read_to_string(file_path) { Ok(file) => match toml::from_str(&file) { Ok(stored_config) => stored_config, Err(file_error) => { @@ -19,12 +20,7 @@ pub fn get_config(file_path: &str) -> Config { Err(_) => // No config file { - Config { - scheme: None, - port: None, - mail: None, - lang: None, - } + Config::default() } } }