https://github.com/sifis-home/datta
Rust implementation of RFC6570 - URI Template that can process URI Templates up and to including ones designated Level 4.
https://github.com/sifis-home/datta
Last synced: about 2 months ago
JSON representation
Rust implementation of RFC6570 - URI Template that can process URI Templates up and to including ones designated Level 4.
- Host: GitHub
- URL: https://github.com/sifis-home/datta
- Owner: sifis-home
- License: bsd-3-clause
- Created: 2022-09-09T08:55:34.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-11-24T10:02:41.000Z (over 2 years ago)
- Last Synced: 2025-01-13T06:44:03.328Z (3 months ago)
- Language: Rust
- Size: 39.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# datta
[](https://github.com/sifis-home/datta/actions)
[](https://crates.io/crates/datta)
[](https://docs.rs/datta/)
[](https://deps.rs/repo/github/sifis-home/datta)
[](https://github.com/sifis-home/datta/blob/master/LICENSE)
[](https://codecov.io/gh/sifis-home/datta)`datta` is a Rust implementation of [RFC6570 - URI
Template](http://tools.ietf.org/html/rfc6570) that can process URI Templates up
to and including ones designated as Level 4 by the specification. It passes all
of the tests in the
[uritemplate-test](https://github.com/uri-templates/uritemplate-test) test
suite.It is a fork of [rust-uritemplate](https://github.com/chowdhurya/rust-uritemplate).
## Basic Usage
Variable setting can be chained for nice, clean code.
```rust
let uri = UriTemplate::new("/view/{object:1}/{/object,names}{?query*}")
.set("object", "lakes")
.set("names", &["Erie", "Superior", "Ontario"])
.set("query", &[("size", "15"), ("lang", "en")])
.build();assert_eq!(uri, "/view/l/lakes/Erie,Superior,Ontario?size=15&lang=en");
```It is not possible to set a variable to the value "undefined". Instead, simply
delete the variable if you have already set it.```rust
let mut t = UriTemplate::new("{hello}");
t.set("hello", "Hello World!");
assert_eq!(t.build(), "Hello%20World%21");t.delete("hello");
assert_eq!(t.build(), "");
```The `delete` function returns `true` if the variable existed and `false`
otherwise.## Supported Types
Any type that implements `IntoTemplateVar` can be set as the value of a
`UriTemplate` variable. The following implementations are provided by default
for each type of variable:- Scalar Values: `String`, `&str`
- Lists: `Vec`, `&[String]`, `&[str]`
- Associative Arrays: `Vec<(String, String)>`, `&[(String, String)]`, `&[(&str,
&str)]`, `&HashMap`In addition, you can implement `IntoTemplateVar` for your own types. View the
documentation for `IntoTemplateVar` for information on how that works.## Acknowledgements
This software has been developed in the scope of the H2020 project SIFIS-Home
with GA n. 952652.