From 7dcd078a2bf1bda98d1a18f699a350c2c7ba7253 Mon Sep 17 00:00:00 2001 From: EliasSchriefer Date: Sat, 10 Jul 2021 13:30:18 +0000 Subject: [PATCH] Move Config into its own module --- src/config.rs | 19 +++++++++++++++++++ src/main.rs | 24 +++++------------------- 2 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 src/config.rs diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..42dda81 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,19 @@ +use serde::{ + Deserialize, + Serialize, +}; +use std::path::PathBuf; + +#[derive(Debug, Serialize, Deserialize)] +#[serde(default, rename_all = "kebab-case")] +pub struct Config { + pub database_path: PathBuf, +} + +impl Default for Config { + fn default() -> Self { + Config { + database_path: crate::DEFAULT_DATABASE_PATH.into(), + } + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index ace0340..0dc1e9e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,10 +4,6 @@ use std::{ boxed::Box, error::Error, }; -use serde::{ - Deserialize, - Serialize, -}; use sqlx::{ prelude::*, sqlite::{ @@ -21,26 +17,16 @@ use tokio::{ fs::File, io::AsyncReadExt, }; -use crate::cli::Options; +use crate::{ + cli::Options, + config::Config, +}; mod cli; +mod config; const DEFAULT_DATABASE_PATH: &'static str = "/var/lib/noise-server/noise-server.sqlite"; -#[derive(Debug, Serialize, Deserialize)] -#[serde(default, rename_all = "kebab-case")] -struct Config { - database_path: PathBuf, -} - -impl Default for Config { - fn default() -> Self { - Config { - database_path: DEFAULT_DATABASE_PATH.into(), - } - } -} - #[tokio::main] async fn main() -> Result<(), Box> { let clap_matches = Options::clap().get_matches();