made_core/value_objects/ceremony/
lifecycle_reason.rs1use crate::error::DomainError;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(try_from = "String", into = "String")]
6pub struct LifecycleReason(String);
7
8impl LifecycleReason {
9 pub const MAX_LEN: usize = 1000;
10 pub fn new(value: impl Into<String>) -> Result<Self, DomainError> {
11 let value = value.into();
12 let value = value.trim();
13 if value.is_empty() {
14 return Err(DomainError::EmptyField {
15 field: "lifecycle_reason",
16 });
17 }
18 if value.len() > Self::MAX_LEN {
19 return Err(DomainError::FieldTooLong {
20 field: "lifecycle_reason",
21 actual: value.len(),
22 max: Self::MAX_LEN,
23 });
24 }
25 Ok(Self(value.to_owned()))
26 }
27 #[must_use]
28 pub fn as_str(&self) -> &str {
29 &self.0
30 }
31}
32impl TryFrom<String> for LifecycleReason {
33 type Error = DomainError;
34 fn try_from(value: String) -> Result<Self, Self::Error> {
35 Self::new(value)
36 }
37}
38impl From<LifecycleReason> for String {
39 fn from(value: LifecycleReason) -> Self {
40 value.0
41 }
42}