Skip to main content

Crate xsd

Crate xsd 

Source
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§

ParseTemporalErrorjiff
A temporal parsing error exposed through core::error::Error.
TimezoneLossError
A conversion to a civil value would discard an explicit timezone.
TimezoneOffset
A validated XSD timezone offset in whole minutes east of UTC.

Enums§

DecimalType
The xsd:decimal datatype hierarchy.
DecimalValue
Value representation for xsd:decimal datatypes.
ParseCalendarError
A partial-calendar lexical, range, or representation error.
ParseDecimalError
An error encountered when parsing an xsd:decimal literal.
ParseError
An error encountered when parsing an XSD literal.
ParseFloatError
An error encountered when parsing an XSD floating-point literal.
PrimitiveType
The XSD primitive datatype hierarchy.
PrimitiveValue
Value representation for XSD primitive datatypes.
TimezoneOffsetError
An invalid XSD timezone-offset spelling or value.
Type
An XSD datatype.
Value
An XSD value.

Constants§

ANY_URI
The xsd:anyURI primitive datatype.
BASE64_BINARY
The xsd:base64Binary primitive datatype.
BASE_URI
The XSD namespace base URI (http://www.w3.org/2001/XMLSchema#).
BOOLEAN
The xsd:boolean primitive datatype.
BYTE
The xsd:byte derived datatype.
DATE
The xsd:date primitive datatype.
DATE_TIME
The xsd:dateTime primitive datatype.
DECIMAL
The xsd:decimal primitive datatype.
DOUBLE
The xsd:double primitive datatype.
DURATION
The xsd:duration primitive datatype.
FLOAT
The xsd:float primitive datatype.
G_DAY
The xsd:gDay primitive datatype.
G_MONTH
The xsd:gMonth primitive datatype.
G_MONTH_DAY
The xsd:gMonthDay primitive datatype.
G_YEAR
The xsd:gYear primitive datatype.
G_YEAR_MONTH
The xsd:gYearMonth primitive datatype.
HEX_BINARY
The xsd:hexBinary primitive datatype.
INT
The xsd:int derived datatype.
INTEGER
The xsd:integer derived datatype.
LONG
The xsd:long derived datatype.
QNAME
The xsd:QName primitive datatype.
SHORT
The xsd:short derived datatype.
STRING
The xsd:string primitive datatype.
TIME
The xsd:time primitive 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:boolean literal.
parse_byte
Parses an input string containing an xsd:byte literal.
parse_datejiff
Parses an input string containing an xsd:date literal.
parse_datetimejiff
Parses an input string containing an xsd:dateTime literal.
parse_decimal
Parses an input string containing an xsd:decimal literal.
parse_double
Parses an input string containing an xsd:double literal.
parse_durationjiff
Parses an input string containing an xsd:duration literal.
parse_float
Parses an input string containing an xsd:float literal.
parse_g_day
Parses an xsd:gDay literal (---dd and an optional timezone).
parse_g_month
Parses an xsd:gMonth using XSD 1.1 syntax (--mm and an optional timezone).
parse_g_month_day
Parses an xsd:gMonthDay literal (--mm-dd and an optional timezone).
parse_g_year
Parses an xsd:gYear with an optional timezone, using XSD 1.1 year numbering.
parse_g_year_month
Parses an xsd:gYearMonth literal (yyyy-mm and an optional timezone).
parse_int
Parses an input string containing an xsd:int literal.
parse_integer
Parses an input string containing an xsd:integer literal.
parse_long
Parses an input string containing an xsd:long literal.
parse_short
Parses an input string containing an xsd:short literal.
parse_stringalloc
Parses an input string containing an xsd:string literal.
parse_timejiff
Parses an input string containing an xsd:time literal.

Type Aliases§

ParseBooleanError
An error encountered when parsing an xsd:boolean literal.
ParseDateTimeErrorjiff
An error encountered when parsing an xsd:dateTime literal.
ParseDoubleError
An error encountered when parsing an xsd:double literal.
ParseDurationErrorjiff
An error encountered when parsing an xsd:duration literal.
ParseIntegerError
An error encountered when parsing an integer-family literal.