Crates.io | uritemplate |
lib.rs | uritemplate |
version | 0.1.2 |
source | src |
created_at | 2015-05-28 02:38:31.612939 |
updated_at | 2016-05-14 06:23:31.973082 |
description | Rust implementation of RFC6570 - URI Template that can processURI Templates up and to including ones designated Level 4. |
homepage | https://github.com/chowdhurya/rust-uritemplate/ |
repository | https://github.com/chowdhurya/rust-uritemplate/ |
max_upload_size | |
id | 2234 |
size | 109,347 |
rust-uritemplate
is a Rust implementation of
RFC6570 - URI Template 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 test
suite.
Variable setting can be chained for nice, clean code.
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.
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.
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:
String
, &str
Vec<String>
, &[String]
, &[str]
Vec<(String, String)>
, &[(String, String)]
,
&[(&str, &str)]
, &HashMap<String, String>
In addition, you can implement IntoTemplateVar
for your own types. View the
documentation for IntoTemplateVar
for information on how that works.