archunit/slices/uml/
plantuml_dependency.rsuse super::PlantUmlError;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PlantUmlDependency {
pub source: String,
pub target: String,
}
impl PlantUmlDependency {
pub fn new(
source: impl Into<String>,
target: impl Into<String>,
) -> Result<Self, PlantUmlError> {
Ok(Self {
source: validated_component_name(source.into())?,
target: validated_component_name(target.into())?,
})
}
}
pub(super) fn validated_component_name(value: String) -> Result<String, PlantUmlError> {
let value = value.trim();
if value.is_empty() {
return Err(PlantUmlError::new("component names must not be empty"));
}
if value.contains([']', '\r', '\n']) {
return Err(PlantUmlError::new(
"component names must not contain ']' or a line break",
));
}
Ok(value.to_owned())
}