[][src]Struct uritemplate::UriTemplate

pub struct UriTemplate { /* fields omitted */ }

The main struct that processes and builds URI Templates.

Implementations

impl UriTemplate[src]

pub fn new(template: &str) -> UriTemplate[src]

Creates a new URI Template from the given template string.

Example

This example is not tested
let t = UriTemplate::new("http://example.com/{name}");

pub fn set<I: IntoTemplateVar>(
    &mut self,
    varname: &str,
    var: I
) -> &mut UriTemplate
[src]

Sets the value of a variable in the URI Template.

Example

This example is not tested
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.

This example is not tested
let uri = UriTemplate::new("{firstname}/{lastname}")
    .set("firstname", "John")
    .set("lastname", "Smith")
    .build();
assert_eq!(uri, "John/Smith");

pub fn delete(&mut self, varname: &str) -> bool[src]

Deletes the value of a variable in the URI Template. Returns true if the variable existed and false otherwise.

Example

This example is not tested
let mut t = UriTemplate::new("{animal}");
t.set("animal", "dog");
assert_eq!(t.delete("house"), false);
assert_eq!(t.delete("animal"), true);

pub fn delete_all(&mut self)[src]

Deletes the values of all variables currently set in the URITemplate.

pub fn build(&self) -> String[src]

Expands the template using the set variable values and returns the final String.

Example

This example is not tested
let mut t = UriTemplate::new("{hello}");
t.set("hello", "Hello World!");
assert_eq!(t.build(), "Hello%20World%21");

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.