23 lines
598 B
Rust
23 lines
598 B
Rust
use config::{Config, File};
|
|
use std::{path::PathBuf, time::Duration};
|
|
pub struct Settings {
|
|
pub photo_path: PathBuf,
|
|
pub duration: Duration,
|
|
}
|
|
|
|
impl Settings {
|
|
pub fn new(settings_file: PathBuf) -> anyhow::Result<Self> {
|
|
let settings = Config::builder()
|
|
.add_source(File::from(settings_file))
|
|
.build()?;
|
|
|
|
let photo_path = settings.get_string("photo_path")?.try_into()?;
|
|
let duration = settings.get_int("duration")?;
|
|
|
|
Ok(Self {
|
|
photo_path,
|
|
duration: Duration::from_secs(duration as u64),
|
|
})
|
|
}
|
|
}
|