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
use std::{
    fmt::{
        Debug,
        Display,
    },
    rc::Rc,
    ops::Deref,
    hash::Hash,
};

#[derive(Clone, Eq, PartialEq, Hash, Debug, PartialOrd, Ord)]
pub struct SchemaTableId(pub String);

impl Display for SchemaTableId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        Display::fmt(&self.0, f)
    }
}

#[derive(Debug)]
pub struct Table_ {
    pub schema_id: SchemaTableId,
    pub id: String,
}

#[derive(Clone, Debug)]
pub struct Table(pub Rc<Table_>);

impl Hash for Table {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.0.schema_id.hash(state)
    }
}

impl PartialEq for Table {
    fn eq(&self, other: &Self) -> bool {
        self.schema_id == other.schema_id
    }
}

impl Eq for Table { }

impl Deref for Table {
    type Target = Table_;

    fn deref(&self) -> &Self::Target {
        self.0.as_ref()
    }
}

impl Display for Table {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        Display::fmt(&format!("{} ({})", self.id, self.schema_id.0), f)
    }
}