Skip to main content

outbox_core/
object.rs

1use serde::{Deserialize, Serialize};
2use std::fmt::Debug;
3use uuid::Uuid;
4
5#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
6#[cfg_attr(feature = "sqlx", sqlx(transparent))]
7#[derive(Debug, Copy, Clone)]
8pub struct EventId(Uuid);
9impl Default for EventId {
10    fn default() -> Self {
11        Self(Uuid::new_v4())
12    }
13}
14impl EventId {
15    pub fn load(id: Uuid) -> Self {
16        Self(id)
17    }
18    pub fn as_uuid(&self) -> Uuid {
19        self.0
20    }
21}
22
23#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
24#[cfg_attr(feature = "sqlx", sqlx(transparent))]
25#[derive(Debug, Clone)]
26pub struct IdempotencyToken(pub String);
27impl IdempotencyToken {
28    pub fn new(token: String) -> Self {
29        Self(token)
30    }
31    pub fn as_str(&self) -> &str {
32        &self.0
33    }
34    pub fn as_bytes(&self) -> &[u8] {
35        self.0.as_bytes()
36    }
37}
38
39#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
40#[cfg_attr(feature = "sqlx", sqlx(transparent))]
41#[derive(Debug)]
42pub struct EventType(String);
43impl EventType {
44    pub fn new(event_type: &str) -> Self {
45        Self(event_type.to_string())
46    }
47    pub fn load(value: &str) -> Self {
48        Self(value.to_owned())
49    }
50    pub fn as_str(&self) -> &str {
51        &self.0
52    }
53}
54
55#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
56#[cfg_attr(feature = "sqlx", sqlx(transparent))]
57#[derive(Debug, Serialize, Deserialize)]
58#[serde(transparent)]
59pub struct Payload<T>(T);
60impl<T> Payload<T>
61where
62    T: Debug + Clone + Serialize + Send + Sync,
63{
64    pub fn new(payload: T) -> Self {
65        Self(payload)
66    }
67    pub fn load(value: &T) -> Self {
68        Self(value.clone())
69    }
70}