takoyaki_core 1.2.0

Core package to build plugins for takoyaki
Documentation
// Import all dependencies
use crate::{Paths, TakoyakiError};
use serde::{Deserialize, Serialize};
use std::fs::read_to_string;

// Main config type
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
    pub unicode: Unicode,
    pub colors: serde_yaml::Value,
    pub cache: CacheConfig,
}

// Unicode config
#[derive(Debug, Serialize, Deserialize)]
pub struct Unicode {
    pub character: String,
    pub paint_bg: bool,
}

// Cache config
#[derive(Debug, Serialize, Deserialize)]
pub struct CacheConfig {
    pub interval: i64,
}

impl Config {
    /// Returns a new instance of config
    ///
    /// # Examples
    ///
    /// ```
    /// use takoyaki_core::Config;
    /// let config = Config::new();
    /// ```
    pub fn new() -> Result<Self, TakoyakiError> {
        // Get the config path
        let path = Paths::get_config_path();

        // Read the config as a string
        let raw = read_to_string(path)?;

        // Parse it to self type
        Ok(serde_yaml::from_str(&raw)?)
    }
}