Skip to main content

DataType

Enum DataType 

Source
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 Serialize and Deserialize for JSON/YAML support
  • Type Mapping: Works with DataTypeOf trait 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)

Implementations§

Source§

impl DataType

Source

pub const fn as_str(&self) -> &'static str

Get the string representation of the data type.

§Returns

Returns the name string of the data type.

Trait Implementations§

Source§

impl Clone for DataType

Source§

fn clone(&self) -> DataType

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for DataType

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for DataType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for DataType

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for DataType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for DataType

Source§

fn eq(&self, other: &DataType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for DataType

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for DataType

Source§

impl Eq for DataType

Source§

impl StructuralPartialEq for DataType

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoResult<T> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,