pub mod config;
pub mod filament;
pub mod job;
pub mod printer;
pub fn parse_margins(csv: &str) -> Result<Vec<f64>, Box<dyn std::error::Error>> {
let margins = csv
.split(',')
.map(|s| {
s.trim()
.parse::<f64>()
.map_err(|_parse_err| format!("invalid --margin entry {s:?}"))
})
.collect::<Result<Vec<f64>, _>>()?;
if let Some(bad) = margins.iter().find(|m| **m >= 100.0 || **m < 0.0) {
return Err(format!(
"margin of {bad}% is out of range — a margin is the share of the sale price that isn't cost, so it must be 0-99 (a 60% markup is a 37.5% margin)"
)
.into());
}
Ok(margins)
}