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
66
67
68
69
70
71
72
73
74
75
76
use crate::{MetadataSchema, Serializable};
use ronky_derive::Serializable as SerializableDerive;
/// Represents a schema for a type in an Arri schema.
///
/// This struct defines the type, optional metadata, and nullability
/// associated with the schema.
#[derive(Debug, PartialEq, Eq, SerializableDerive)]
pub struct TypeSchema {
/// The type of the schema.
r#type: Types,
/// Optional metadata associated with the schema.
metadata: Option<MetadataSchema>,
/// Indicates whether the schema allows null values. If `Some(true)`,
/// null values are permitted.
is_nullable: Option<bool>,
}
impl TypeSchema {
/// Creates a new `TypeSchema` instance with the specified type.
///
/// # Arguments
///
/// * `r#type` - The type of the schema.
///
/// # Returns
///
/// A new `TypeSchema` instance with default values for metadata and nullability.
pub fn new(r#type: Types) -> Self {
Self {
r#type,
metadata: None,
is_nullable: None,
}
}
}
#[derive(Debug, PartialEq, Eq)]
pub enum Types {
String,
Boolean,
Timestamp,
Float32,
Float64,
Int8,
Uint8,
Int16,
Uint16,
Int32,
Uint32,
Int64,
Uint64,
}
impl Serializable for Types {
fn serialize(&self) -> Option<String> {
(match self {
Self::String => "string",
Self::Boolean => "boolean",
Self::Timestamp => "timestamp",
Self::Float32 => "float32",
Self::Float64 => "float64",
Self::Int8 => "int8",
Self::Uint8 => "uint8",
Self::Int16 => "int16",
Self::Uint16 => "uint16",
Self::Int32 => "int32",
Self::Uint32 => "uint32",
Self::Int64 => "int64",
Self::Uint64 => "uint64",
})
.serialize()
}
}