use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct AnatomyConfig {
#[serde(rename = "layer")]
pub layers: Vec<LayerConfig>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct LayerConfig {
pub name: String,
pub height_pct: f32,
pub density: f32,
pub composition: HashMap<String, f32>,
}
impl AnatomyConfig {
pub fn parse(src: &str) -> Result<Self, String> {
toml::from_str(src).map_err(|e| format!("TOML parse error: {}", e))
}
pub fn load(path: &std::path::Path) -> Result<Self, String> {
let content = std::fs::read_to_string(path)
.map_err(|e| format!("Failed to read file {:?}: {}", path, e))?;
Self::parse(&content)
}
}
#[cfg(test)]
#[path = "test_anatomy.rs"]
mod test_anatomy;