konduto/types/device/language.rs
1use crate::impl_nutype_error_conversion;
2use nutype::nutype;
3
4/// Idioma do dispositivo (mínimo 2, máximo 225 caracteres)
5///
6/// # Validações
7/// - Não pode ser vazio (após trim)
8/// - Mínimo 2 caracteres
9/// - Máximo 225 caracteres
10///
11/// # Exemplos
12/// ```
13/// use konduto::language::DeviceLanguage;
14///
15/// let language = DeviceLanguage::try_new("pt-BR").unwrap();
16/// assert_eq!(language.as_str(), "pt-BR");
17/// ```
18#[nutype(
19 sanitize(trim),
20 validate(not_empty, len_char_min = 2, len_char_max = 225),
21 derive(
22 Debug,
23 Clone,
24 PartialEq,
25 Eq,
26 Display,
27 AsRef,
28 Deref,
29 Serialize,
30 Deserialize,
31 )
32)]
33pub struct DeviceLanguage(String);
34
35impl DeviceLanguage {
36 /// Retorna o idioma como string slice (compatibilidade)
37 pub fn as_str(&self) -> &str {
38 self.as_ref()
39 }
40}
41
42impl_nutype_error_conversion!(DeviceLanguageError);