qubit-datatype

Runtime data type descriptors and conversion utilities for Rust

Rust CI Coverage Crates.io Rust License

Runtime data type descriptors and conversion utilities for Rust.

Overview

Qubit Datatype provides a shared DataType enum, compile-time type mapping through DataTypeOf, and reusable conversion utilities for moving values between supported Rust data types. It is intended for libraries that need runtime type metadata, typed empty values, configuration parsing, value containers, or structured conversion diagnostics.

Design Goals

Features

Data Type System

Data Conversion

Installation

Add this to your Cargo.toml:

[dependencies]
qubit-datatype = "0.2"

Quick Start

Data Type Usage

use qubit_datatype::{DataType, DataTypeOf};

let data_type = DataType::Int32;
assert_eq!(data_type.as_str(), "int32");

assert_eq!(i32::DATA_TYPE, DataType::Int32);
assert_eq!(String::DATA_TYPE, DataType::String);

Data Conversion

use std::time::Duration;

use qubit_datatype::{
    DataConversionResult,
    DataConverter,
    DataConverters,
    DataListConversionResult,
};

fn read_settings() -> DataConversionResult<(u16, bool, Duration)> {
    let port = DataConverter::from("8080").to::<u16>()?;
    let enabled = DataConverter::from("true").to::<bool>()?;
    let timeout = DataConverter::from("1500000000ns").to::<Duration>()?;

    Ok((port, enabled, timeout))
}

fn read_ports(values: &[String]) -> DataListConversionResult<Vec<u16>> {
    DataConverters::from(values).to_vec()
}

Conversion Options

use qubit_datatype::{
    BlankStringPolicy,
    DataConversionOptions,
    DataConverter,
};

let options = DataConversionOptions::default()
    .with_blank_string_policy(BlankStringPolicy::AsNone);

let value = DataConverter::from(" 8080 ")
    .to_with::<u16>(&options)
    .expect("port should convert");

assert_eq!(value, 8080);

Supported Data Types

The DataType enum lists every variant. String forms use as_str().

Basic Types

Date, Time, and Structured Types

API Reference

Data Types

Conversion

Testing & Code Coverage

This project maintains comprehensive test coverage for data type parsing, mapping, conversion success paths, conversion errors, and boundary conditions.

Running Tests

# Run all tests
cargo test

# Run with coverage report
./coverage.sh

# Generate text format report
./coverage.sh text

# Run CI checks (format, clippy, test, coverage, audit)
./ci-check.sh

Coverage Metrics

See COVERAGE.md for detailed coverage statistics.

Dependencies

Runtime dependencies:

License

Copyright (c) 2025 - 2026. Haixing Hu, Qubit Co. Ltd. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

See LICENSE for the full license text.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Guidelines

Author

Haixing Hu - Qubit Co. Ltd.

More Rust libraries from Qubit are published under the qubit-ltd organization on GitHub.

---

Repository: https://github.com/qubit-ltd/rs-datatype