native_db_32bit/watch/
event.rs

1use crate::db_type::{DatabaseOutputValue, Input};
2use std::fmt::Debug;
3
4#[derive(Clone)]
5pub enum Event {
6    Insert(Insert),
7    Update(Update),
8    Delete(Delete),
9}
10
11impl Event {
12    pub(crate) fn new_insert(value: DatabaseOutputValue) -> Self {
13        Self::Insert(Insert(value))
14    }
15
16    pub(crate) fn new_update(
17        old_value: DatabaseOutputValue,
18        new_value: DatabaseOutputValue,
19    ) -> Self {
20        Self::Update(Update {
21            old: old_value,
22            new: new_value,
23        })
24    }
25
26    pub(crate) fn new_delete(value: DatabaseOutputValue) -> Self {
27        Self::Delete(Delete(value))
28    }
29}
30
31impl Debug for Event {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        match self {
34            Event::Insert(_) => write!(f, "Insert"),
35            Event::Update(_) => write!(f, "Update"),
36            Event::Delete(_) => write!(f, "Delete"),
37        }
38    }
39}
40
41#[derive(Clone)]
42pub struct Insert(pub(crate) DatabaseOutputValue);
43
44impl Insert {
45    pub fn inner<T: Input>(&self) -> T {
46        self.0.inner()
47    }
48}
49
50#[derive(Clone)]
51pub struct Update {
52    pub(crate) old: DatabaseOutputValue,
53    pub(crate) new: DatabaseOutputValue,
54}
55
56impl Update {
57    pub fn inner_old<T: Input>(&self) -> T {
58        self.old.inner()
59    }
60    pub fn inner_new<T: Input>(&self) -> T {
61        self.new.inner()
62    }
63}
64
65#[derive(Clone)]
66pub struct Delete(pub(crate) DatabaseOutputValue);
67
68impl Delete {
69    pub fn inner<T: Input>(&self) -> T {
70        self.0.inner()
71    }
72}