# XSD.rs: XML Schema for Rust
[](https://unlicense.org)
[](https://blog.rust-lang.org/2025/02/20/Rust-1.85.0/)
[](https://crates.io/crates/xsd)
[](https://docs.rs/xsd)
**XSD.rs** is a [Rust] implementation of the [XML Schema] datatypes.
> [!TIP]
> 🚧 _We are building in public. This is presently under heavy construction._
<sub>
[[Features](#-features)] |
[[Prerequisites](#%EF%B8%8F-prerequisites)] |
[[Installation](#%EF%B8%8F-installation)] |
[[Examples](#-examples)] |
[[Reference](#-reference)] |
[[Development](#%E2%80%8D-development)]
</sub>
## ✨ 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
```bash
cargo add xsd
```
### Installation in `Cargo.toml`
Enable all default features:
```toml
[dependencies]
xsd = { version = "0.3" }
```
Enable only specific features:
```toml
[dependencies]
xsd = { version = "0.3", default-features = false, features = ["alloc"] }
```
## 👉 Examples
### Importing the Library
```rust
use xsd::{Type, Value};
use xsd::primitive::{Boolean, Date, DateTime, Decimal, Double, Duration, Float, Time};
```
### Parsing XSD Literals
```rust
# 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
```rust
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
```rust
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
```rust
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](https://docs.rs/xsd)
## 👨💻 Development
```bash
git clone https://github.com/rust-rdf/rdf.rs.git
```
---
[](https://x.com/intent/post?url=https://github.com/rust-rdf/rdf.rs/tree/master/lib/xsd&text=XSD.rs)
[](https://reddit.com/submit?url=https://github.com/rust-rdf/rdf.rs/tree/master/lib/xsd&title=XSD.rs)
[](https://news.ycombinator.com/submitlink?u=https://github.com/rust-rdf/rdf.rs/tree/master/lib/xsd&t=XSD.rs)
[](https://www.facebook.com/sharer/sharer.php?u=https://github.com/rust-rdf/rdf.rs/tree/master/lib/xsd)
[](https://www.linkedin.com/sharing/share-offsite/?url=https://github.com/rust-rdf/rdf.rs/tree/master/lib/xsd)
[feature flags]: https://github.com/rust-rdf/rdf.rs/blob/master/lib/xsd/Cargo.toml
[naming conventions]: https://rust-lang.github.io/api-guidelines/naming.html
[Rust]: https://rust-lang.org
[XML Schema]: http://www.w3.org/TR/xmlschema-2/