use default trait

This commit is contained in:
Mylloon 2023-02-09 11:42:33 +01:00
parent d57231cfc4
commit 6b932d45ba
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,6 +1,7 @@
use serde::Deserialize;
use std::fs;
#[derive(Deserialize, Clone)]
#[derive(Deserialize, Clone, Default)]
pub struct Config {
pub scheme: Option<String>,
pub port: Option<u16>,
@ -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()
}
}
}