ines-core 0.0.2

Rust bundler/framework for website with WebComponent
Documentation
use crate::project::error::Result;

use serde::{Deserialize, Serialize};
use std::path::PathBuf;

#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
    pub version: usize,
    pub out: PathBuf,
    pub generate_redirects: Option<Vec<String>>,
}

impl Config {
    pub fn from_file(path: &PathBuf) -> Result<Self> {
        let content = std::fs::read_to_string(path)?;
        toml::from_str(&content).map_err(Into::into)
    }

    pub fn write_to_file(&self, path: &PathBuf) -> Result<()> {
        std::fs::write(path, toml::to_string_pretty(self)?).map_err(Into::into)
    }
}

impl Default for Config {
    fn default() -> Self {
        Self {
            version: 0,
            out: PathBuf::from("out"),
            generate_redirects: None,
        }
    }
}