konduto/types/customer/customer_name.rs
1use crate::impl_nutype_error_conversion;
2use nutype::nutype;
3
4/// Nome do cliente (máximo 100 caracteres)
5///
6/// # Validações
7/// - Não pode ser vazio (após trim)
8/// - Máximo 100 caracteres
9/// - Whitespace é removido automaticamente (trim)
10///
11/// # Exemplos
12/// ```
13/// use konduto::customer_name::CustomerName;
14///
15/// let name = CustomerName::try_new("João Silva").unwrap();
16/// assert_eq!(name.as_str(), "João Silva");
17///
18/// // String vazia é rejeitada
19/// assert!(CustomerName::try_new("").is_err());
20///
21/// // String muito longa é rejeitada
22/// assert!(CustomerName::try_new("a".repeat(101)).is_err());
23/// ```
24#[nutype(
25 sanitize(trim),
26 validate(not_empty, len_char_max = 100),
27 derive(
28 Debug,
29 Clone,
30 PartialEq,
31 Eq,
32 Display,
33 AsRef,
34 Deref,
35 Serialize,
36 Deserialize,
37 )
38)]
39pub struct CustomerName(String);
40
41impl CustomerName {
42 /// Retorna o nome como string slice (compatibilidade)
43 pub fn as_str(&self) -> &str {
44 self.as_ref()
45 }
46}
47
48// Conversão do erro gerado pelo nutype para nosso ValidationError
49impl_nutype_error_conversion!(CustomerNameError);