vcard/values/
uid_value.rs1use std::fmt::Display;
2
3use validators::{Validated, ValidatedWrapper};
4
5use super::{text::Text, uri::URI, uuid::UUID, *};
6
7#[derive(Clone, Debug, PartialEq, Eq, Hash)]
8#[allow(clippy::upper_case_acronyms)]
9pub enum UIDValue {
10 URI(URI),
11 UUID(UUID),
12 Text(Text),
13}
14
15impl UIDValue {
16 pub fn is_empty(&self) -> bool {
17 if let UIDValue::Text(t) = self {
18 return t.is_empty();
19 }
20
21 false
22 }
23}
24
25impl Value for UIDValue {
26 fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
27 if self.is_empty() {
28 return Ok(());
29 }
30
31 match self {
32 UIDValue::URI(uri) => {
33 Value::fmt(uri, f)?;
34 },
35 UIDValue::UUID(uuid) => {
36 Value::fmt(uuid, f)?;
37 },
38 UIDValue::Text(t) => {
39 Value::fmt(t, f)?;
40 },
41 }
42
43 Ok(())
44 }
45}
46
47impl Display for UIDValue {
48 fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
49 Value::fmt(self, f)
50 }
51}
52
53impl Validated for UIDValue {}
54
55impl ValidatedWrapper for UIDValue {
56 type Error = &'static str;
57
58 fn from_string(_from_string_input: String) -> Result<Self, Self::Error> {
59 unimplemented!();
60 }
61
62 fn from_str(_from_str_input: &str) -> Result<Self, Self::Error> {
63 unimplemented!();
64 }
65}