Documentation

XSD.rs: XML Schema for Rust

License Compatibility Package Documentation

XSD.rs is a Rust implementation of the XML Schema datatypes.

[!TIP] 🚧 We are building in public. This is presently under heavy construction.

[Features] | [Prerequisites] | [Installation] | [Examples] | [Reference] | [Development]

✨ Features

  • 100% pure and safe Rust with minimal dependencies and no bloat.
  • Supports no_std environments from the get-go.
  • Supports opting out of any feature using comprehensive feature flags.
  • Adheres to the Rust API Guidelines in its naming conventions.
  • Cuts red tape: 100% free and unencumbered public domain software.

🛠️ Prerequisites

  • Rust 1.85+ (2024 edition)

⬇️ Installation

Installation via Cargo

cargo add xsd

Installation in Cargo.toml

Enable all default features:

[dependencies]
xsd = { version = "0.3" }

Enable only specific features:

[dependencies]
xsd = { version = "0.3", default-features = false, features = ["alloc"] }

👉 Examples

Importing the Library

use xsd::{Type, Value};
use xsd::primitive::{Boolean, Date, DateTime, Decimal, Double, Duration, Float, Time};

Parsing XSD Literals

# fn main() -> Result<(), Box<dyn core::error::Error>> {
let value = xsd::parse("Hello, world!", xsd::STRING)?;
let value = xsd::parse("true", xsd::BOOLEAN)?;
let value = xsd::parse("3.1415", xsd::DOUBLE)?;
let value = xsd::parse("42", xsd::INT)?;
let value = xsd::parse("2026-12-31", xsd::DATE)?;
let value = xsd::parse("2026-12-31T12:34:56", xsd::DATE_TIME)?;
# Ok(())
# }

Constructing XSD Values

let value: xsd::Value = "Hello, world!".into();
let value: xsd::Value = true.into();
let value: xsd::Value = 3.1415.into();
let value: xsd::Value = 42.into();

Matching XSD Values

use xsd::Value::*;

let value = xsd::parse("3.1415", xsd::DOUBLE).unwrap();

match value {
    Decimal(value) => eprintln!("{:?}", value),
    Primitive(value) => eprintln!("{:?}", value),
}

Matching XSD Decimals

use xsd::DecimalValue::*;

let value = xsd::parse("3.1415", xsd::DECIMAL).unwrap();

match value.as_decimal() {
    Decimal(_) => eprintln!("it's an xsd:decimal"),
    Integer(_) => eprintln!("it's an xsd:integer"),
    Long(_) => eprintln!("it's an xsd:long"),
    Int(_) => eprintln!("it's an xsd:int"),
    Short(_) => eprintln!("it's an xsd:short"),
    Byte(_) => eprintln!("it's an xsd:byte"),
    _ => unreachable!(),
}

📚 Reference

docs.rs/xsd

👨‍💻 Development

git clone https://github.com/rust-rdf/rdf.rs.git

Share on X Share on Reddit Share on Hacker News Share on Facebook Share on LinkedIn