Skip to main content

unitycatalog_common/models/
association.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(
4    Debug,
5    Clone,
6    Deserialize,
7    Serialize,
8    PartialEq,
9    Hash,
10    Eq,
11    strum::AsRefStr,
12    strum::Display,
13    strum::EnumString,
14)]
15#[serde(rename_all = "snake_case")]
16#[strum(serialize_all = "snake_case")]
17#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
18#[cfg_attr(
19    feature = "sqlx",
20    sqlx(type_name = "association_label", rename_all = "snake_case")
21)]
22pub enum AssociationLabel {
23    OwnedBy,
24    OwnerOf,
25    DependsOn,
26    DependencyOf,
27    ParentOf,
28    ChildOf,
29    HasPart,
30    PartOf,
31    References,
32    ReferencedBy,
33    /// An entity is tagged with a tag (entity -> tag policy).
34    Tagged,
35    /// A tag is applied to an entity (tag policy -> entity); inverse of `Tagged`.
36    TaggedBy,
37}
38
39impl AssociationLabel {
40    /// Get the inverse of the association label.
41    ///
42    /// Associations may be bidirectional, either symmetric or asymmetric.
43    /// Symmetric types are their own inverse. Asymmetric types have a distinct inverse.
44    pub fn inverse(&self) -> Option<Self> {
45        match self {
46            AssociationLabel::HasPart => Some(AssociationLabel::PartOf),
47            AssociationLabel::PartOf => Some(AssociationLabel::HasPart),
48            AssociationLabel::DependsOn => Some(AssociationLabel::DependencyOf),
49            AssociationLabel::DependencyOf => Some(AssociationLabel::DependsOn),
50            AssociationLabel::ParentOf => Some(AssociationLabel::ChildOf),
51            AssociationLabel::ChildOf => Some(AssociationLabel::ParentOf),
52            AssociationLabel::References => Some(AssociationLabel::ReferencedBy),
53            AssociationLabel::ReferencedBy => Some(AssociationLabel::References),
54            AssociationLabel::OwnedBy => Some(AssociationLabel::OwnerOf),
55            AssociationLabel::OwnerOf => Some(AssociationLabel::OwnedBy),
56            AssociationLabel::Tagged => Some(AssociationLabel::TaggedBy),
57            AssociationLabel::TaggedBy => Some(AssociationLabel::Tagged),
58        }
59    }
60}