20 lines
419 B
Rust
20 lines
419 B
Rust
use config::Config;
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct Settings {
|
|
pub host: String,
|
|
pub port: u16,
|
|
pub database_url: String,
|
|
}
|
|
|
|
impl Settings {
|
|
pub fn new() -> Result<Self, config::ConfigError> {
|
|
let settings = Config::builder()
|
|
.add_source(config::File::with_name("settings"))
|
|
.build()?;
|
|
|
|
settings.try_deserialize()
|
|
}
|
|
}
|