1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use std::collections::BTreeMap;
5
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
7#[serde(tag = "kind", rename_all = "snake_case")]
8pub enum CanonicalValue {
9 Null,
10 Absent,
11 Bool {
12 value: bool,
13 },
14 Integer {
15 value: String,
16 },
17 Decimal {
18 value: String,
19 },
20 Float {
21 value: String,
22 },
23 String {
24 value: String,
25 },
26 Bytes {
27 base64: String,
28 media_type: Option<String>,
29 },
30 Array {
31 items: Vec<CanonicalValue>,
32 },
33 Object {
34 fields: BTreeMap<String, CanonicalValue>,
35 },
36 DateTime {
37 rfc3339: String,
38 },
39 Json {
40 value: Value,
41 },
42}
43
44impl CanonicalValue {
45 #[must_use]
46 pub fn kind_name(&self) -> &'static str {
47 match self {
48 Self::Null => "null",
49 Self::Absent => "absent",
50 Self::Bool { .. } => "bool",
51 Self::Integer { .. } => "integer",
52 Self::Decimal { .. } => "decimal",
53 Self::Float { .. } => "float",
54 Self::String { .. } => "string",
55 Self::Bytes { .. } => "bytes",
56 Self::Array { .. } => "array",
57 Self::Object { .. } => "object",
58 Self::DateTime { .. } => "date_time",
59 Self::Json { .. } => "json",
60 }
61 }
62}