konduto/types/device/browser.rs
1use nutype::nutype;
2use crate::impl_nutype_error_conversion;
3
4/// Navegador 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::browser::DeviceBrowser;
14///
15/// let browser = DeviceBrowser::try_new("Chrome").unwrap();
16/// assert_eq!(browser.as_str(), "Chrome");
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 DeviceBrowser(String);
34
35impl DeviceBrowser {
36 /// Retorna o navegador como string slice (compatibilidade)
37 pub fn as_str(&self) -> &str {
38 self.as_ref()
39 }
40}
41
42impl_nutype_error_conversion!(DeviceBrowserError);