Expand description
XML Schema (XSD) datatypes for Rust.
§Features
Disable defaults for no_std. Numeric values and datatype identifiers are
available without this crate’s alloc feature; alloc enables owned strings
and allocation-dependent helpers. datetime (also exposed as jiff) enables
date/time values without requiring std. serde and borsh imply alloc;
bson, oxrdf, and rudof require std. Defaults enable all and std.
Dependency features are forwarded explicitly; enabling serialization does
not implicitly enable date/time support.
use xsd::{Type, Value};
use xsd::primitive::{Boolean, Decimal, Double, Duration, Float};
use xsd::primitive::{Date, DateTime, Time};§Sophia interoperability
The sophia feature is currently an empty compatibility placeholder. It
enables no dependencies, trait implementations, or conversion APIs in this
crate, and does not enable alloc or std. In particular, enabling it does
not make Value or PrimitiveValue implement Sophia term traits.
Applications integrating with Sophia must provide their own term conversion,
retaining RDF lexical forms and datatype identifiers outside parsed values.
§JSON-LD interoperability
The json-ld feature is currently an empty compatibility placeholder. It
enables no dependencies, JSON-LD processing, or conversion APIs, and does not
enable alloc, std, or serde. Explicit JSON conversion methods on values
require the separate serde feature. Those methods produce JSON values,
not JSON-LD value objects carrying @value and @type; they do not provide
JSON-LD expansion, compaction, or RDF datatype-preserving round trips.
§Rudof interoperability
The rudof feature enables std (and thus alloc) and the optional
oxsdatatypes dependency. It currently provides no dedicated Rudof or
oxsdatatypes conversion API, trait implementations, or public re-exports.
It also does not enable datetime or change which datatypes parse
supports. Applications using oxsdatatypes directly must declare their own
dependency and handle conversion and representation limits explicitly.
§Borsh interoperability
The borsh feature enables BorshSerialize and BorshDeserialize for
Type, PrimitiveType, DecimalType, DecimalValue, and
TimezoneOffset. It also
forwards Borsh support to the numeric backend and enables alloc, without
requiring std.
With jiff as well, primitive::Date, primitive::Time, and
primitive::DateTime support versioned, validated type-local encodings
documented on those types. primitive::GMonth, primitive::GDay,
primitive::GMonthDay, and primitive::GYearMonth have
versioned, validated encodings available without date/time features; see
their migration notes.
Value and PrimitiveValue do not implement Borsh serialization or
deserialization, even with borsh enabled. Wrapping a supported numeric
value in either enum does not make that wrapper serializable.
The supported enums use structural binary encodings, not XSD lexical strings. Round trips preserve their variants and stored data; they cannot recover original lexical spelling that was discarded during parsing. This feature does not define a versioned, cross-release interchange format.
§Borsh examples
Supported types round-trip through Borsh (requires borsh):
fn round_trip<T>(value: T)
where
T: borsh::BorshSerialize + borsh::BorshDeserialize + PartialEq + core::fmt::Debug,
{
let bytes = borsh::to_vec(&value).unwrap();
assert_eq!(borsh::from_slice::<T>(&bytes).unwrap(), value);
}
round_trip(xsd::DATE);
round_trip(xsd::PrimitiveType::Date);
round_trip(xsd::DecimalType::Int);
round_trip(xsd::DecimalValue::Int(42));The general value wrapper is intentionally outside this supported boundary:
let value = xsd::Value::from(xsd::DecimalValue::Int(42));
let bytes = borsh::to_vec(&value).unwrap();The primitive wrapper likewise does not implement Borsh deserialization:
let value = borsh::from_slice::<xsd::PrimitiveValue>(&[]).unwrap();Modules§
- derived
- Rust types for representing values of XSD derived datatypes.
- primitive
- Rust types for representing values of XSD primitive datatypes.
Structs§
- Parse
Temporal Error jiff - A temporal parsing error exposed through
core::error::Error. - Timezone
Loss Error - A conversion to a civil value would discard an explicit timezone.
- Timezone
Offset - A validated XSD timezone offset in whole minutes east of UTC.
Enums§
- Decimal
Type - The
xsd:decimaldatatype hierarchy. - Decimal
Value - Value representation for
xsd:decimaldatatypes. - Parse
Calendar Error - A partial-calendar lexical, range, or representation error.
- Parse
Decimal Error - An error encountered when parsing an
xsd:decimalliteral. - Parse
Error - An error encountered when parsing an XSD literal.
- Parse
Float Error - An error encountered when parsing an XSD floating-point literal.
- Primitive
Type - The XSD primitive datatype hierarchy.
- Primitive
Value - Value representation for XSD primitive datatypes.
- Timezone
Offset Error - An invalid XSD timezone-offset spelling or value.
- Type
- An XSD datatype.
- Value
- An XSD value.
Constants§
- ANY_URI
- The
xsd:anyURIprimitive datatype. - BASE64_
BINARY - The
xsd:base64Binaryprimitive datatype. - BASE_
URI - The XSD namespace base URI (
http://www.w3.org/2001/XMLSchema#). - BOOLEAN
- The
xsd:booleanprimitive datatype. - BYTE
- The
xsd:bytederived datatype. - DATE
- The
xsd:dateprimitive datatype. - DATE_
TIME - The
xsd:dateTimeprimitive datatype. - DECIMAL
- The
xsd:decimalprimitive datatype. - DOUBLE
- The
xsd:doubleprimitive datatype. - DURATION
- The
xsd:durationprimitive datatype. - FLOAT
- The
xsd:floatprimitive datatype. - G_DAY
- The
xsd:gDayprimitive datatype. - G_MONTH
- The
xsd:gMonthprimitive datatype. - G_
MONTH_ DAY - The
xsd:gMonthDayprimitive datatype. - G_YEAR
- The
xsd:gYearprimitive datatype. - G_
YEAR_ MONTH - The
xsd:gYearMonthprimitive datatype. - HEX_
BINARY - The
xsd:hexBinaryprimitive datatype. - INT
- The
xsd:intderived datatype. - INTEGER
- The
xsd:integerderived datatype. - LONG
- The
xsd:longderived datatype. - QNAME
- The
xsd:QNameprimitive datatype. - SHORT
- The
xsd:shortderived datatype. - STRING
- The
xsd:stringprimitive datatype. - TIME
- The
xsd:timeprimitive datatype.
Statics§
- TYPES
- A PHF map from XSD typenames to datatypes.
Functions§
- parse
- Parses an input string containing an XSD literal.
- parse_
boolean - Parses an input string containing an
xsd:booleanliteral. - parse_
byte - Parses an input string containing an
xsd:byteliteral. - parse_
date jiff - Parses an input string containing an
xsd:dateliteral. - parse_
datetime jiff - Parses an input string containing an
xsd:dateTimeliteral. - parse_
decimal - Parses an input string containing an
xsd:decimalliteral. - parse_
double - Parses an input string containing an
xsd:doubleliteral. - parse_
duration jiff - Parses an input string containing an
xsd:durationliteral. - parse_
float - Parses an input string containing an
xsd:floatliteral. - parse_
g_ day - Parses an
xsd:gDayliteral (---ddand an optional timezone). - parse_
g_ month - Parses an
xsd:gMonthusing XSD 1.1 syntax (--mmand an optional timezone). - parse_
g_ month_ day - Parses an
xsd:gMonthDayliteral (--mm-ddand an optional timezone). - parse_
g_ year - Parses an
xsd:gYearwith an optional timezone, using XSD 1.1 year numbering. - parse_
g_ year_ month - Parses an
xsd:gYearMonthliteral (yyyy-mmand an optional timezone). - parse_
int - Parses an input string containing an
xsd:intliteral. - parse_
integer - Parses an input string containing an
xsd:integerliteral. - parse_
long - Parses an input string containing an
xsd:longliteral. - parse_
short - Parses an input string containing an
xsd:shortliteral. - parse_
string alloc - Parses an input string containing an
xsd:stringliteral. - parse_
time jiff - Parses an input string containing an
xsd:timeliteral.
Type Aliases§
- Parse
Boolean Error - An error encountered when parsing an
xsd:booleanliteral. - Parse
Date Time Error jiff - An error encountered when parsing an
xsd:dateTimeliteral. - Parse
Double Error - An error encountered when parsing an
xsd:doubleliteral. - Parse
Duration Error jiff - An error encountered when parsing an
xsd:durationliteral. - Parse
Integer Error - An error encountered when parsing an integer-family literal.