remindrs/src/config.rs
finga d37f31dd8a Add config file parsing
Use the `serde` and `toml` crates to handle config file parsing.
2023-01-24 01:19:20 +01:00

48 lines
941 B
Rust

use serde::Deserialize;
fn default_host() -> String {
"localhost".to_string()
}
const fn default_port() -> u16 {
5432
}
fn default_name() -> String {
"whakarite".to_string()
}
fn default_user() -> String {
"whakarite".to_string()
}
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Database {
/// Host of the database
#[serde(default = "default_host")]
pub host: String,
/// Port of the database
#[serde(default = "default_port")]
pub port: u16,
/// Name of the database
#[serde(default = "default_name")]
pub name: String,
/// Name of the user to connect to the database
#[serde(default = "default_user")]
pub user: String,
/// Password of the user to connect to the database
pub pass: String,
}
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
/// Database configuration
pub database: Database,
}