use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BoundarySpec {
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
#[serde(default)]
pub boundaries: Vec<BoundaryDef>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BoundaryDef {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(default)]
pub modules: Vec<String>,
#[serde(default)]
pub allow_imports_from: Vec<String>,
}
impl BoundarySpec {
pub fn to_yaml(&self) -> String {
serde_yml::to_string(self).unwrap_or_default()
}
#[cfg(feature = "loader")]
pub fn load(path: &std::path::Path) -> Result<Option<Self>, crate::ConfigError> {
let content = match std::fs::read_to_string(path) {
Ok(c) => c,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None),
Err(e) => return Err(crate::ConfigError::Io(e)),
};
let spec: Self = serde_yml::from_str(&content)
.map_err(|e| crate::ConfigError::BoundaryParse(e.to_string()))?;
Ok(Some(spec))
}
}