Add config file parsing
Use the `serde` and `toml` crates to handle config file parsing.
This commit is contained in:
parent
665015c296
commit
d37f31dd8a
5 changed files with 160 additions and 12 deletions
47
src/config.rs
Normal file
47
src/config.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
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,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue