native_db/watch/
event.rs

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