#![forbid(unsafe_code)]
pub mod paths;
pub mod profile;
use std::path::Path;
pub use paths::default_profile_path;
pub use profile::{ModalStyle, Profile};
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("parse error: {0}")]
Parse(#[from] toml::de::Error),
#[error("serialize error: {0}")]
Serialize(#[from] toml::ser::Error),
}
pub fn read(path: &Path) -> Result<Profile, Error> {
let text = std::fs::read_to_string(path)?;
Ok(toml::from_str(&text)?)
}
pub fn write(path: &Path, profile: &Profile) -> Result<(), Error> {
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent)?;
}
let text = toml::to_string_pretty(profile)?;
std::fs::write(path, text)?;
Ok(())
}