32 lines
771 B
Rust
32 lines
771 B
Rust
use serde::{Deserialize, Serialize};
|
|
use std::{
|
|
collections::HashMap,
|
|
fs::File,
|
|
io::{Error, ErrorKind, Read},
|
|
path::PathBuf,
|
|
};
|
|
use toml::from_str;
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
pub struct Config {
|
|
pub workspace_directory: String,
|
|
pub max_depth: usize,
|
|
pub project_marker: Vec<String>,
|
|
pub directories: HashMap<String, DirectoryConfig>,
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
struct DirectoryConfig {
|
|
pub priority: u32,
|
|
pub icon: String,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn load(path: PathBuf) -> Result<Self, Error> {
|
|
let mut file = File::open(path)?;
|
|
let mut contents = String::new();
|
|
file.read_to_string(&mut contents)?;
|
|
|
|
from_str(&contents).map_err(|e| Error::new(ErrorKind::InvalidData, e))
|
|
}
|
|
}
|