mirror of
https://github.com/anthonyoteri/dredge.git
synced 2026-06-05 15:26:53 -04:00
31 lines
648 B
Rust
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)
|
|
}
|
|
}
|