isoflux_core/
event.rs

1use std::fmt::Debug;
2
3use crate::generation::FluxGeneration;
4use crate::reexport::*;
5
6pub trait FluxEventPayload: Clone + Debug {}
7
8#[derive(Clone, Debug, CopyGetters)]
9pub struct FluxEvent<P>
10where
11    P: FluxEventPayload,
12{
13    #[getset(get_copy = "pub")]
14    id: Uuid,
15    #[getset(get_copy = "pub")]
16    timestamp: Timestamp,
17    #[getset(get_copy = "pub")]
18    generation: FluxGeneration,
19    #[getset(get = "pub")]
20    payload: P,
21}
22
23impl<P> FluxEvent<P>
24where
25    P: FluxEventPayload,
26{
27    pub fn new<G>(generation: G, payload: P) -> Self
28    where
29        G: Into<FluxGeneration>,
30    {
31        Self {
32            id: Uuid::new_v4(),
33            timestamp: Utc::now(),
34            generation: generation.into(),
35            payload,
36        }
37    }
38}