| Crates.io | uri-template |
| lib.rs | uri-template |
| version | 0.1.0 |
| created_at | 2026-01-02 11:15:29.112314+00 |
| updated_at | 2026-01-02 11:15:29.112314+00 |
| description | RFC6570 URI Template library for Rust, with parsing, expansion, compile-time checked macros, and no_std support. |
| homepage | https://github.com/gntzh/uri-template |
| repository | https://github.com/gntzh/uri-template |
| max_upload_size | |
| id | 2018382 |
| size | 9,112 |
A Rust Implementation of RFC6570 URI Template with parsing, expansion, compile-time checked macros, and no_std support.
uri-template = { version = "0.1.0", features = ["macros"] }
no_std support.Basic usage:
use uri_template::{HashValues, UriTemplate};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let template = UriTemplate::new("https://example.com/{username}/items{?page,pageSize}")?;
let mut values = HashValues::new();
values.insert("username", "foo");
values.insert("page", 1);
values.insert("pageSize", 20);
let uri = template.expand(&values)?;
assert_eq!(uri, "https://example.com/foo/items?page=1&pageSize=20");
Ok(())
}
Compile-time checked templates:
use uri_template::{HashValues, uri_template};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let template = uri_template!("https://example.com/{username}/items{?page,pageSize}");
let mut values = HashValues::new();
values.insert("username", "foo");
values.insert("page", 1);
values.insert("pageSize", 20);
let uri = template.expand(&values)?;
assert_eq!(uri, "https://example.com/foo/items?page=1&pageSize=20");
Ok(())
}
The macro checks template validity at compile time and generates optimized code.
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.