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
use std::fmt::Display;

use chrono::{DateTime, Utc};
use uuid::Uuid;

/**
A Dataverse AttributeValue for use in query filters

Please note that this enum is for use in queries only as it is not serializable
*/
#[derive(Clone, Debug)]
pub enum Attribute {
    /// Indicates a `null` value
    Null,

    /// Indicates a boolean value like `true` or `false`
    Boolean(bool),

    /// Indicates a 64-bit signed integer
    Integer(i64),

    /// Indicates a 64-bit floating decimal number
    Decimal(f64),

    /// Indicates a string of characters
    String(String),

    /// Indicates a date and time expressed as UTC
    DateTime(DateTime<Utc>),

    /// Indicates an Universally Unique Identifier
    Uuid(Uuid),
}

impl Display for Attribute {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Attribute::Null => f.write_str("null"),
            Attribute::Boolean(value) => f.write_fmt(format_args!("{}", value)),
            Attribute::Integer(value) => f.write_fmt(format_args!("{}", value)),
            Attribute::Decimal(value) => f.write_fmt(format_args!("{}", value)),
            Attribute::String(value) => f.write_fmt(format_args!("'{}'", value)),
            Attribute::DateTime(value) => f.write_fmt(format_args!("'{}'", value)),
            Attribute::Uuid(value) => f.write_fmt(format_args!("'{}'", value.as_hyphenated())),
        }
    }
}