Skip to main content

made_core/value_objects/outbox/
outbox_attempt.rs

1use serde::{Deserialize, Serialize};
2
3/// How many times delivery of a message has been tried.
4///
5/// Counted by the store rather than carried by the message: a message
6/// states what happened in the ceremony, and how hard it has been to
7/// publish is not part of that.
8#[derive(
9    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize,
10)]
11#[serde(transparent)]
12pub struct OutboxAttempt(u32);
13
14impl OutboxAttempt {
15    pub const NONE: Self = Self(0);
16
17    #[must_use]
18    pub fn new(value: u32) -> Self {
19        Self(value)
20    }
21
22    #[must_use]
23    pub fn value(self) -> u32 {
24        self.0
25    }
26
27    #[must_use]
28    pub fn next(self) -> Self {
29        Self(self.0.saturating_add(1))
30    }
31
32    #[must_use]
33    pub fn is_exhausted(self, max_attempts: u32) -> bool {
34        self.0 >= max_attempts
35    }
36}