powerplatform_dataverse_service_client/query/
attribute.rs

1use std::fmt::Display;
2
3use chrono::{DateTime, Utc};
4use uuid::Uuid;
5
6/**
7A Dataverse AttributeValue for use in query filters
8
9Please note that this enum is for use in queries only as it is not serializable
10*/
11#[derive(Clone, Debug)]
12pub enum Attribute {
13    /// Indicates a `null` value
14    Null,
15
16    /// Indicates a boolean value like `true` or `false`
17    Boolean(bool),
18
19    /// Indicates a 64-bit signed integer
20    Integer(i64),
21
22    /// Indicates a 64-bit floating decimal number
23    Decimal(f64),
24
25    /// Indicates a string of characters
26    String(String),
27
28    /// Indicates a date and time expressed as UTC
29    DateTime(DateTime<Utc>),
30
31    /// Indicates an Universally Unique Identifier
32    Uuid(Uuid),
33}
34
35impl Display for Attribute {
36    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        match self {
38            Attribute::Null => f.write_str("null"),
39            Attribute::Boolean(value) => f.write_fmt(format_args!("{}", value)),
40            Attribute::Integer(value) => f.write_fmt(format_args!("{}", value)),
41            Attribute::Decimal(value) => f.write_fmt(format_args!("{}", value)),
42            Attribute::String(value) => f.write_fmt(format_args!("'{}'", value)),
43            Attribute::DateTime(value) => f.write_fmt(format_args!("'{}'", value)),
44            Attribute::Uuid(value) => f.write_fmt(format_args!("'{}'", value.as_hyphenated())),
45        }
46    }
47}