XSD.rs: XML Schema for Rust

🚧 This is presently under heavy construction.
✨ 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.
- 100% free and unencumbered public domain software.
🛠️ Prerequisites
- Rust 1.85+ (2024 edition)
⬇️ Installation
Installation via Cargo
cargo add xsd
Installation in Cargo.toml (with all features enabled)
[dependencies]
xsd = { version = "0.3" }
👉 Examples
Importing the library
use xsd::{Type, Value};
use xsd::primitives::{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
https://docs.rs/xsd
👨💻 Development
git clone https://github.com/rust-rdf/rdf.rs.git
