native_db_32bit/watch/
event.rs

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
use crate::db_type::{DatabaseOutputValue, Input};
use std::fmt::Debug;

#[derive(Clone)]
pub enum Event {
    Insert(Insert),
    Update(Update),
    Delete(Delete),
}

impl Event {
    pub(crate) fn new_insert(value: DatabaseOutputValue) -> Self {
        Self::Insert(Insert(value))
    }

    pub(crate) fn new_update(
        old_value: DatabaseOutputValue,
        new_value: DatabaseOutputValue,
    ) -> Self {
        Self::Update(Update {
            old: old_value,
            new: new_value,
        })
    }

    pub(crate) fn new_delete(value: DatabaseOutputValue) -> Self {
        Self::Delete(Delete(value))
    }
}

impl Debug for Event {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Event::Insert(_) => write!(f, "Insert"),
            Event::Update(_) => write!(f, "Update"),
            Event::Delete(_) => write!(f, "Delete"),
        }
    }
}

#[derive(Clone)]
pub struct Insert(pub(crate) DatabaseOutputValue);

impl Insert {
    pub fn inner<T: Input>(&self) -> T {
        self.0.inner()
    }
}

#[derive(Clone)]
pub struct Update {
    pub(crate) old: DatabaseOutputValue,
    pub(crate) new: DatabaseOutputValue,
}

impl Update {
    pub fn inner_old<T: Input>(&self) -> T {
        self.old.inner()
    }
    pub fn inner_new<T: Input>(&self) -> T {
        self.new.inner()
    }
}

#[derive(Clone)]
pub struct Delete(pub(crate) DatabaseOutputValue);

impl Delete {
    pub fn inner<T: Input>(&self) -> T {
        self.0.inner()
    }
}