Struct uritemplate::UriTemplate
[−]
[src]
pub struct UriTemplate { /* fields omitted */ }
The main struct that processes and builds URI Templates.
Methods
impl UriTemplate
[src]
fn new(template: &str) -> UriTemplate
Creates a new URI Template from the given template string.
Example
let t = UriTemplate::new("http://example.com/{name}");
fn set<I: IntoTemplateVar>(&mut self, varname: &str, var: I) -> &mut UriTemplate
Sets the value of a variable in the URI Template.
Example
let mut t = UriTemplate::new("{name}"); t.set("name", "John Smith");
This function returns the URITemplate
so that the set()
calls can
be chained before building.
let uri = UriTemplate::new("{firstname}/{lastname}") .set("firstname", "John") .set("lastname", "Smith") .build(); assert_eq!(uri, "John/Smith");
fn delete(&mut self, varname: &str) -> bool
Deletes the value of a variable in the URI Template. Returns true
if
the variable existed and false
otherwise.
Example
let mut t = UriTemplate::new("{animal}"); t.set("animal", "dog"); assert_eq!(t.delete("house"), false); assert_eq!(t.delete("animal"), true);
fn delete_all(&mut self)
Deletes the values of all variables currently set in the URITemplate
.
fn build(&self) -> String
Expands the template using the set variable values and returns the final String.
Example
let mut t = UriTemplate::new("{hello}"); t.set("hello", "Hello World!"); assert_eq!(t.build(), "Hello%20World%21");