Files
dredge/src/config.rs
T
2023-09-18 14:01:21 -04:00

31 lines
648 B
Rust

use std::fs;
use std::path::Path;
use serde::{Deserialize, Serialize};
use url::Url;
use crate::error::ConfigError;
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct Config {
pub registry_url: Url,
}
impl Default for Config {
fn default() -> Self {
Self {
registry_url: Url::parse("https://localhost:5000").unwrap(),
}
}
}
impl TryFrom<&Path> for Config {
type Error = ConfigError;
fn try_from(path: &Path) -> Result<Self, Self::Error> {
let contents = fs::read_to_string(path)?;
let config: Self = toml::from_str(&contents)?;
Ok(config)
}
}