made_core/value_objects/ceremony/
step_instructions.rs1use serde::{Deserialize, Serialize};
2
3use crate::error::DomainError;
4
5const MAX_STEP_INSTRUCTIONS: usize = 16_384;
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(transparent)]
10pub struct StepInstructions(String);
11
12impl StepInstructions {
13 pub fn new(value: impl Into<String>) -> Result<Self, DomainError> {
14 let value = value.into();
15 let trimmed = value.trim();
16 if trimmed.is_empty() {
17 return Err(DomainError::EmptyField {
18 field: "step_instructions",
19 });
20 }
21 if trimmed.chars().count() > MAX_STEP_INSTRUCTIONS {
22 return Err(DomainError::FieldTooLong {
23 field: "step_instructions",
24 max: MAX_STEP_INSTRUCTIONS,
25 actual: trimmed.chars().count(),
26 });
27 }
28 Ok(Self(trimmed.to_owned()))
29 }
30
31 #[must_use]
32 pub fn as_str(&self) -> &str {
33 &self.0
34 }
35}