Skip to main content

made_core/value_objects/ceremony/
step_attempt.rs

1use serde::{Deserialize, Serialize};
2
3use crate::error::DomainError;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
6#[serde(transparent)]
7pub struct StepAttempt(u32);
8
9impl StepAttempt {
10    pub const FIRST: Self = Self(1);
11
12    pub fn new(value: u32) -> Result<Self, DomainError> {
13        if value == 0 {
14            return Err(DomainError::MustBeNonZero {
15                field: "step_attempt",
16            });
17        }
18        Ok(Self(value))
19    }
20
21    pub fn next(self) -> Result<Self, DomainError> {
22        Self::new(self.0.saturating_add(1))
23    }
24
25    #[must_use]
26    pub fn get(self) -> u32 {
27        self.0
28    }
29}