made_core/value_objects/ceremony/
ceremony_description.rs1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4
5use crate::error::DomainError;
6
7const MAX_DESCRIPTION_LEN: usize = 4096;
8
9#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
10#[serde(transparent)]
11pub struct CeremonyDescription(String);
12
13impl CeremonyDescription {
14 pub fn new(raw: impl Into<String>) -> Result<Self, DomainError> {
15 let value = raw.into();
16 let trimmed = value.trim();
17 if trimmed.is_empty() {
18 return Err(DomainError::EmptyField {
19 field: "ceremony_description",
20 });
21 }
22 if trimmed.len() > MAX_DESCRIPTION_LEN {
23 return Err(DomainError::FieldTooLong {
24 field: "ceremony_description",
25 actual: trimmed.len(),
26 max: MAX_DESCRIPTION_LEN,
27 });
28 }
29 if trimmed.chars().any(char::is_control) {
30 return Err(DomainError::InvalidCharacters {
31 field: "ceremony_description",
32 });
33 }
34 Ok(Self(trimmed.to_owned()))
35 }
36
37 #[must_use]
38 pub fn as_str(&self) -> &str {
39 &self.0
40 }
41}
42
43impl fmt::Display for CeremonyDescription {
44 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45 f.write_str(&self.0)
46 }
47}