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
use std::{
rc::Rc,
ops::Deref,
fmt::Display,
};
use super::{
field::Field,
table::Table,
};
#[derive(Clone, Eq, PartialEq, Hash, Debug, PartialOrd, Ord)]
pub struct SchemaIndexId(pub String);
impl Display for SchemaIndexId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.0, f)
}
}
pub struct Index_ {
pub table: Table,
pub schema_id: SchemaIndexId,
pub id: String,
pub fields: Vec<Field>,
pub unique: bool,
}
#[derive(Clone)]
pub struct Index(pub Rc<Index_>);
impl Display for Index {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
Display::fmt(
&format!("{}.{} ({}.{})", self.0.table.id, self.0.id, self.0.table.schema_id, self.0.schema_id),
f,
)
}
}
impl PartialEq for Index {
fn eq(&self, other: &Self) -> bool {
self.table == other.table && self.schema_id == other.schema_id
}
}
impl Eq for Index { }
impl Deref for Index {
type Target = Index_;
fn deref(&self) -> &Self::Target {
self.0.as_ref()
}
}