ic_dbms_api/dbms/
types.rs

1//! This module exposes the data types used in the DBMS canister.
2
3use candid::CandidType;
4use serde::{Deserialize, Serialize};
5
6use crate::dbms::value::Value;
7use crate::memory::Encode;
8
9mod blob;
10mod boolean;
11mod date;
12mod datetime;
13mod decimal;
14mod int32;
15mod int64;
16mod nullable;
17mod principal;
18mod text;
19mod uint32;
20mod uint64;
21mod uuid;
22
23pub use self::blob::Blob;
24pub use self::boolean::Boolean;
25pub use self::date::Date;
26pub use self::datetime::DateTime;
27pub use self::decimal::Decimal;
28pub use self::int32::Int32;
29pub use self::int64::Int64;
30pub use self::nullable::Nullable;
31pub use self::principal::Principal;
32pub use self::text::Text;
33pub use self::uint32::Uint32;
34pub use self::uint64::Uint64;
35pub use self::uuid::Uuid;
36
37/// A trait representing a data type that can be stored in the DBMS.
38///
39/// This is an umbrella trait that combines several other traits to ensure that
40/// any type implementing [`DataType`] can be cloned, compared, hashed, encoded,
41/// and serialized/deserialized using both Candid and Serde.
42///
43/// Also it is used by the DBMS to compare and sort values of different data types.
44pub trait DataType:
45    Clone
46    + std::fmt::Debug
47    + std::fmt::Display
48    + PartialEq
49    + Eq
50    + PartialOrd
51    + Ord
52    + std::hash::Hash
53    + Encode
54    + CandidType
55    + Serialize
56    + Into<Value>
57    + for<'de> Deserialize<'de>
58{
59}
60
61/// An enumeration of all supported data type kinds in the DBMS.
62#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
63pub enum DataTypeKind {
64    Blob,
65    Boolean,
66    Date,
67    DateTime,
68    Decimal,
69    Int32,
70    Int64,
71    Principal,
72    Text,
73    Uint32,
74    Uint64,
75    Uuid,
76}