#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Relationship {
Implements,
Depends,
Transforms,
Aggregates,
Invokes,
Produces,
Consumes,
Validates,
Configures,
Unknown,
}
impl Relationship {
pub fn as_str(&self) -> &'static str {
match self {
Self::Implements => "Implements",
Self::Depends => "Depends",
Self::Transforms => "Transforms",
Self::Aggregates => "Aggregates",
Self::Invokes => "Invokes",
Self::Produces => "Produces",
Self::Consumes => "Consumes",
Self::Validates => "Validates",
Self::Configures => "Configures",
Self::Unknown => "Unknown",
}
}
}
impl std::fmt::Display for Relationship {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_relationship_equality() {
assert_eq!(Relationship::Implements, Relationship::Implements);
assert_ne!(Relationship::Implements, Relationship::Depends);
}
#[test]
fn test_relationship_as_str() {
assert_eq!(Relationship::Implements.as_str(), "Implements");
assert_eq!(Relationship::Depends.as_str(), "Depends");
}
#[test]
fn test_relationship_display() {
let rel = Relationship::Implements;
assert_eq!(format!("{}", rel), "Implements");
}
}