Qubit Datatype
Runtime data type descriptors and policy-driven conversion utilities for Rust.
Installation
The default build contains the lightweight type vocabulary only:
[]
= "0.5"
Enable individual external type mappings as needed, or enable the complete conversion engine:
[]
= { = "0.5", = ["converter"] }
Features
| Feature | Adds |
|---|---|
| default | No optional dependencies |
| chrono | DataTypeOf for Chrono date/time types |
| big-number | DataTypeOf for BigInt and BigDecimal |
| url | DataTypeOf for Url |
| json | DataTypeOf for JSON values |
| converter | The conversion API and all rich-type features |
Type vocabulary
DataType provides 27 stable runtime type names, an exhaustive ALL array,
numeric classification methods, Serde support, and case-insensitive parsing.
DataTypeOf maps Rust types to their runtime descriptors.
use ;
assert_eq!;
assert!;
assert_eq!;
Conversion contract
With the converter feature, DataConverter converts a single value,
DataConverters converts an iterator, and ScalarStringDataConverters
lazily splits a scalar string while preserving original source indices.
The default NumericConversionPolicy::Exact rejects truncation, rounding, and
precision loss. Select Lossy explicitly to allow finite decimal/float to
integer truncation toward zero, integer-to-float IEEE rounding, and Duration
half-up rounding.
#
#
Conversion matrix
“Numeric” below includes primitive integers/floats and arbitrary-precision
numbers. Invalid values return InvalidValue; type pairs outside this matrix return
Unsupported; typed empty values return Missing.
| Source family | Supported targets |
|---|---|
| Any concrete source | Its own type; String |
String |
Numeric, bool, char, Chrono types, Duration, URL, JSON, StringMap |
| Bool / char | Primitive numeric targets |
| Integer / BigInt | Numeric targets, bool, Duration |
| Float / BigDecimal | Numeric targets |
| Duration | Integer targets and String |
| StringMap | JSON and String |
| JSON | String |
Strings and booleans
Strings are not trimmed by default. Every string conversion calls
StringConversionOptions::normalize once; enable trim explicitly.
Blank strings can be preserved, treated as missing, or rejected.
Boolean text defaults to only true and false (ASCII
case-insensitive). Numeric 0/1 handling is controlled separately by
BooleanNumericPolicy::ZeroOrOne; NonZero and Reject are explicit
alternatives. Literal builders are fallible, so true/false sets cannot overlap.
#
#
Duration
Duration text uses [0-9]+(ns|us|µs|μs|ms|s|m|h|d)?. Numeric input,
suffixless strings, and output formatting have independent unit policies;
the default profile uses milliseconds for all three. Whitespace, signs, and
decimals are rejected. Large integer counts are decomposed into seconds and
nanoseconds before range checking.
Duration-to-integer and Duration-to-String follow the numeric policy: Exact requires divisibility by the configured output unit; Lossy rounds half-up.
Rich text formats
- char: exactly one Unicode scalar value
- date:
YYYY-MM-DD - time:
HH:MM:SS[.fraction], 1–9 fractional digits - local date-time:
YYYY-MM-DDTHH:MM:SS[.fraction] - UTC instant: RFC 3339 with
Zor an offset - BigInt: signed decimal integer
- BigDecimal: decimal with optional exponent
- URL: absolute URL
- JSON: any valid JSON value
- StringMap: JSON object with unique keys and string values
Structured errors and collections
DataConversionError has exactly four variants: Missing, EmptyCollection,
Unsupported, and InvalidValue { reason }. Missing, Unsupported, and
InvalidValue store source and target DataType; EmptyCollection stores only
the target type. Errors never retain or display the original value.
List failures use DataListConversionError::source_index. Empty-item
Skip does not renumber later items, and to_first stops after the first
retained item without validating the tail.
Development
License
Licensed under the Apache License, Version 2.0. See LICENSE.
Author
Haixing Hu — Qubit Co. Ltd.