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
use crate::{serde::Datum, types::Serializable};
use derive_more::{Deref, From};
use std::borrow::Borrow;
use std::cmp::{Ordering, PartialOrd};
use std::sync::Arc;

#[derive(From, Deref, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub struct PrimaryKey(pub Datum);

pub type PKShared = Arc<PrimaryKey>;

/* PKShared is comparable against PrimaryKey. */
impl PartialEq<PrimaryKey> for PKShared {
    fn eq(&self, other: &PrimaryKey) -> bool {
        (self as &PrimaryKey).eq(other)
    }
}
impl PartialOrd<PrimaryKey> for PKShared {
    fn partial_cmp(&self, other: &PrimaryKey) -> Option<Ordering> {
        (self as &PrimaryKey).partial_cmp(other)
    }
}

/* PKShared is comparable against &PrimaryKey. */
impl PartialEq<&PrimaryKey> for PKShared {
    fn eq(&self, other: &&PrimaryKey) -> bool {
        (self as &PrimaryKey).eq(other)
    }
}
impl PartialOrd<&PrimaryKey> for PKShared {
    fn partial_cmp(&self, other: &&PrimaryKey) -> Option<Ordering> {
        (self as &PrimaryKey).partial_cmp(other)
    }
}

/* PKShared is Serializable. */
impl Borrow<Datum> for PKShared {
    fn borrow(&self) -> &Datum {
        self
    }
}
impl From<Datum> for PKShared {
    fn from(dat: Datum) -> Self {
        Arc::new(PrimaryKey(dat))
    }
}
impl Serializable for PKShared {}