1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::fmt::Display;

use validators::{Validated, ValidatedWrapper};

use super::{text::Text, uri::URI, uuid::UUID, *};

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[allow(clippy::upper_case_acronyms)]
pub enum UIDValue {
    URI(URI),
    UUID(UUID),
    Text(Text),
}

impl UIDValue {
    pub fn is_empty(&self) -> bool {
        if let UIDValue::Text(t) = self {
            return t.is_empty();
        }

        false
    }
}

impl Value for UIDValue {
    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
        if self.is_empty() {
            return Ok(());
        }

        match self {
            UIDValue::URI(uri) => {
                Value::fmt(uri, f)?;
            },
            UIDValue::UUID(uuid) => {
                Value::fmt(uuid, f)?;
            },
            UIDValue::Text(t) => {
                Value::fmt(t, f)?;
            },
        }

        Ok(())
    }
}

impl Display for UIDValue {
    fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
        Value::fmt(self, f)
    }
}

impl Validated for UIDValue {}

impl ValidatedWrapper for UIDValue {
    type Error = &'static str;

    fn from_string(_from_string_input: String) -> Result<Self, Self::Error> {
        unimplemented!();
    }

    fn from_str(_from_str_input: &str) -> Result<Self, Self::Error> {
        unimplemented!();
    }
}