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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use Persistable;
/// To support decoupling between the [`crate::Aggregate::Event`] type and the schema of the DB table
/// in [`super::PgStore`] you can create a schema type that implements [`Persistable`] and [`Schema`]
/// where `E = Aggregate::Event`.
///
/// Note: Although [`Schema::to_event`] returns an [`Option`] for any given event and implementation.
///
/// The following must hold
///
/// ```rust
/// # use serde::{Serialize, Deserialize};
/// # use esrs::store::postgres::Schema as SchemaTrait;
/// #
/// # #[derive(Clone, Eq, PartialEq, Debug)]
/// # struct Event {
/// # a: u32,
/// # }
/// #
/// # #[derive(Serialize, Deserialize)]
/// # struct Schema {
/// # a: u32,
/// # }
/// #
/// # #[cfg(feature = "upcasting")]
/// # impl esrs::event::Upcaster for Schema {}
/// #
/// # impl SchemaTrait<Event> for Schema {
/// # fn from_event(Event { a }: Event) -> Self {
/// # Self { a }
/// # }
/// #
/// # fn to_event(self) -> Option<Event> {
/// # Some(Event { a: self.a })
/// # }
/// # }
/// #
/// # let event = Event { a: 42 };
/// assert_eq!(Some(event.clone()), Schema::from_event(event).to_event());
/// ```