pub enum DataType {
Show 27 variants
Bool,
Char,
Int8,
Int16,
Int32,
Int64,
Int128,
UInt8,
UInt16,
UInt32,
UInt64,
UInt128,
Float32,
Float64,
String,
Date,
Time,
DateTime,
Instant,
BigInteger,
BigDecimal,
IntSize,
UIntSize,
Duration,
Url,
StringMap,
Json,
}Expand description
Universal data type enumeration for cross-module type representation
Defines all basic data types and composite types supported by the system. This enum provides a unified way to represent and work with different data types across various modules and components.
DataType serves as a bridge between Rust’s type system and runtime type
information, enabling dynamic type handling, serialization, validation,
and other type-aware operations.
§Features
- Comprehensive Coverage: Supports all basic Rust types plus common third-party types
- String Representation: Each variant has a consistent string representation
- Serialization Support: Implements
SerializeandDeserializefor JSON/YAML support - Type Mapping: Works with
DataTypeOftrait for compile-time type mapping
§Use Cases
- Dynamic Type Handling: Runtime type checking and conversion
- Serialization/Deserialization: Type-aware data format conversion
- Validation Systems: Type-based input validation
- Generic Programming: Type-safe generic operations
- API Documentation: Automatic type information generation
§Examples
§Basic Usage
use qubit_common::lang::DataType;
let data_type = DataType::Int32;
assert_eq!(data_type.to_string(), "int32");
assert_eq!(data_type.as_str(), "int32");§Type Checking
use qubit_common::lang::DataType;
fn is_numeric(data_type: DataType) -> bool {
matches!(data_type,
DataType::Int8 | DataType::Int16 | DataType::Int32 | DataType::Int64 | DataType::Int128 |
DataType::UInt8 | DataType::UInt16 | DataType::UInt32 | DataType::UInt64 | DataType::UInt128 |
DataType::Float32 | DataType::Float64 | DataType::BigInteger | DataType::BigDecimal
)
}
assert!(is_numeric(DataType::Int32));
assert!(!is_numeric(DataType::String));§Serialization
use qubit_common::lang::DataType;
use serde_json;
let data_type = DataType::Float64;
let json = serde_json::to_string(&data_type).unwrap();
assert_eq!(json, "\"float64\"");
let deserialized: DataType = serde_json::from_str(&json).unwrap();
assert_eq!(deserialized, DataType::Float64);§Author
Haixing Hu
Variants§
Bool
Boolean type
Char
Character type
Int8
8-bit signed integer
Int16
16-bit signed integer
Int32
32-bit signed integer
Int64
64-bit signed integer
Int128
128-bit signed integer
UInt8
8-bit unsigned integer
UInt16
16-bit unsigned integer
UInt32
32-bit unsigned integer
UInt64
64-bit unsigned integer
UInt128
128-bit unsigned integer
Float32
32-bit floating point number
Float64
64-bit floating point number
String
String type
Date
Date type (NaiveDate)
Time
Time type (NaiveTime)
DateTime
DateTime type (NaiveDateTime)
Instant
UTC time point (equivalent to Java Instant) (DateTime<Utc>)
BigInteger
Big integer type (BigInt)
BigDecimal
Big decimal type (BigDecimal)
IntSize
Platform-dependent signed integer (isize)
UIntSize
Platform-dependent unsigned integer (usize)
Duration
Duration type (std::time::Duration)
Url
URL type (url::Url)
StringMap
String map type (HashMap<String, String>)
Json
JSON value type (serde_json::Value)