konduto/types/customer/
customer_id.rs

1use crate::impl_nutype_error_conversion;
2use nutype::nutype;
3
4/// ID do cliente (máximo 100 caracteres)
5///
6/// # Validações
7/// - Não pode ser vazio
8/// - Máximo 100 caracteres
9///
10/// # Exemplos
11/// ```
12///  use konduto::customer_id::CustomerId;
13///
14/// let id = CustomerId::try_new("CUST-123").unwrap();
15/// assert_eq!(id.as_str(), "CUST-123");
16///
17/// // String vazia é rejeitada
18/// assert!(CustomerId::try_new("").is_err());
19/// ```
20#[nutype(
21    sanitize(trim),
22    validate(not_empty, len_char_max = 100),
23    derive(
24        Debug,
25        Clone,
26        PartialEq,
27        Eq,
28        Hash,
29        Display,
30        AsRef,
31        Deref,
32        Serialize,
33        Deserialize,
34    )
35)]
36pub struct CustomerId(String);
37
38impl CustomerId {
39    /// Retorna o ID como string slice (compatibilidade)
40    pub fn as_str(&self) -> &str {
41        self.as_ref()
42    }
43}
44
45impl_nutype_error_conversion!(CustomerIdError);