1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use smile::ffi::DSL_pattern_EdgeType;

#[derive(Eq, PartialEq)]
/// The type of an edge in a pattern
pub enum EdgeType {
    /// An edge that is directed. The first argument is the source node index, the second is the target node index
    Directed(usize, usize),

    /// An edge that is undirected
    Undirected,

    /// An absent edge
    Absent,
}

impl EdgeType {
    pub(super) fn from_dsl(value: DSL_pattern_EdgeType, from: usize, to: usize) -> Self {
        match value {
            DSL_pattern_EdgeType::Directed => Self::Directed(from, to),
            DSL_pattern_EdgeType::Undirected => Self::Undirected,
            DSL_pattern_EdgeType::None => Self::Absent,
        }
    }
}

impl From<EdgeType> for DSL_pattern_EdgeType {
    fn from(value: EdgeType) -> Self {
        match value {
            EdgeType::Directed(_, _) => DSL_pattern_EdgeType::Directed,
            EdgeType::Undirected => DSL_pattern_EdgeType::Undirected,
            EdgeType::Absent => DSL_pattern_EdgeType::None,
        }
    }
}