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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use crate::owl::{Annotation, Axiom, ClassConstructor, Regards, IRI};

/// Defines that the subject is a sub class of the object.
///
/// Structure `(subject, object, annotations)`.
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct SubClassOf(
    /// subject
    pub Box<ClassConstructor>,
    /// object
    pub Box<ClassConstructor>,
    pub Vec<Annotation>,
);

impl SubClassOf {
    pub fn subject(&self) -> &ClassConstructor {
        &self.0
    }
    pub fn parent(&self) -> &ClassConstructor {
        &self.1
    }
    pub fn annotations(&self) -> &Vec<Annotation> {
        &self.2
    }
}

impl From<SubClassOf> for Box<ClassConstructor> {
    fn from(sco: SubClassOf) -> Self {
        Box::new(ClassConstructor::SubClassOf(sco))
    }
}
impl From<SubClassOf> for ClassConstructor {
    fn from(sco: SubClassOf) -> Self {
        ClassConstructor::SubClassOf(sco)
    }
}
// impl<'a> From<&'a SubClassOf> for &'a ClassConstructor {
//     fn from(sco: &'a SubClassOf) -> Self {
//         &ClassConstructor::SubClassOf(*sco)
//     }
// }

impl Regards for SubClassOf {
    fn regards(&self, iri: &IRI) -> bool {
        self.subject().regards(iri) || self.parent().regards(iri)
    }
}

impl ClassConstructor {
    pub fn sub_class_of(&self) -> Option<&SubClassOf> {
        match self {
            ClassConstructor::SubClassOf(s) => Some(s),
            _ => None,
        }
    }
}

impl From<SubClassOf> for Axiom {
    fn from(sco: SubClassOf) -> Self {
        Axiom::SubClassOf(sco)
    }
}

#[cfg(feature = "wasm")]
mod wasm {
    use wasm_bindgen::prelude::wasm_bindgen;
    #[wasm_bindgen(typescript_custom_section)]
    const WASM_API: &'static str = r#"
/**
 * [ClassConstructor, ClassConstructor, Array<Annotation>]
 */
export type SubClassOf = [ClassConstructor, ClassConstructor, Array<Annotation>];
"#;
}