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