You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

49 lines
1.0 KiB

serialize! {
conf:
#[derive(Default)]
pub struct Conf {
pub log: crate::log::Conf,
pub render: crate::render::Conf,
}
}
#[derive(Debug)]
pub enum ErrConfLoad {
NoFile,
File(std::io::Error),
Parse(serde_yaml::Error),
}
impl std::fmt::Display for ErrConfLoad {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NoFile => write!(f, "No existing conf file"),
Self::File(e) => write!(f, "Couldn't open conf file: {}", e),
Self::Parse(e) => write!(f, "Couldn't parse conf file: {}", e),
}
}
}
impl From<std::io::Error> for ErrConfLoad {
fn from(err: std::io::Error) -> Self {
match err.kind() {
std::io::ErrorKind::NotFound => Self::NoFile,
_ => Self::File(err),
}
}
}
impl From<serde_yaml::Error> for ErrConfLoad {
fn from(err: serde_yaml::Error) -> Self {
Self::Parse(err)
}
}
impl Conf {
pub fn read(filename: &'static str) -> Result<Conf, ErrConfLoad> {
let file = std::fs::File::open(filename)?;
Ok(serde_yaml::from_reader(file)?)
}
}
// EOF