sea_query/value/
with_uuid.rs

1use super::*;
2
3type_to_value!(Uuid, Uuid, Uuid);
4
5macro_rules! fmt_uuid_to_box_value {
6    ( $type: ty, $conversion_fn: ident ) => {
7        impl From<$type> for Value {
8            fn from(x: $type) -> Value {
9                Value::Uuid(Some(x.into_uuid()))
10            }
11        }
12
13        impl Nullable for $type {
14            fn null() -> Value {
15                Value::Uuid(None)
16            }
17        }
18
19        impl ValueType for $type {
20            fn try_from(v: Value) -> Result<Self, ValueTypeErr> {
21                match v {
22                    Value::Uuid(Some(x)) => Ok(x.$conversion_fn()),
23                    _ => Err(ValueTypeErr),
24                }
25            }
26
27            fn type_name() -> String {
28                stringify!($type).to_owned()
29            }
30
31            fn array_type() -> ArrayType {
32                ArrayType::Uuid
33            }
34
35            fn column_type() -> ColumnType {
36                ColumnType::Uuid
37            }
38        }
39    };
40}
41
42fmt_uuid_to_box_value!(uuid::fmt::Braced, braced);
43fmt_uuid_to_box_value!(uuid::fmt::Hyphenated, hyphenated);
44fmt_uuid_to_box_value!(uuid::fmt::Simple, simple);
45fmt_uuid_to_box_value!(uuid::fmt::Urn, urn);
46
47impl Value {
48    pub fn is_uuid(&self) -> bool {
49        matches!(self, Self::Uuid(_))
50    }
51    pub fn as_ref_uuid(&self) -> Option<&Uuid> {
52        match self {
53            Self::Uuid(v) => v.as_ref(),
54            _ => panic!("not Value::Uuid"),
55        }
56    }
57}