uritemplate

Struct UriTemplate

Source
pub struct UriTemplate { /* private fields */ }
Expand description

The main struct that processes and builds URI Templates.

Implementations§

Source§

impl UriTemplate

Source

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

Creates a new URI Template from the given template string.

§Example
let t = UriTemplate::new("http://example.com/{name}");
Source

pub 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");
Source

pub 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);
Source

pub fn delete_all(&mut self)

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

Source

pub 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");

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.