[][src]Struct rfc6570_level_2::UriTemplate

pub struct UriTemplate(_);

A template URI validated against RFC6570 Level 2.

Implementations

impl UriTemplate[src]

pub fn new(uri: &str) -> Result<Self>[src]

Validates a string against RFC6570 Level 2; if valid, returns a URI template that can later be expanded.

Examples

use rfc6570_level_2::UriTemplate;

let template = UriTemplate::new("https://example.com/{resource}/{+id}{#field}")?;
assert_eq!(template.uri(), "https://example.com/{resource}/{+id}{#field}");

Errors

An error describing the offending component will be returned in case of a validation failure.

#[must_use]pub fn uri(&self) -> &str[src]

Returns a reference to the string backing the URI template.

Examples

use rfc6570_level_2::UriTemplate;

let template = UriTemplate::new("https://example.com/{resource}/{+id}{#field}")?;
assert_eq!(template.uri(), "https://example.com/{resource}/{+id}{#field}");

pub fn expressions(&self) -> impl Iterator<Item = &str>[src]

Returns an iterator over the expressions contained within the URI template.

Examples

use rfc6570_level_2::UriTemplate;

let template = UriTemplate::new("https://example.com/{resource}/{+id}{#field}")?;
let expressions: Vec<&str> = template.expressions().collect();
assert_eq!(expressions, vec!["{resource}", "{+id}", "{#field}"]);

pub fn variables(&self) -> impl Iterator<Item = &str>[src]

Returns an iterator over the variable definitions contained within the URI template.

Examples

use rfc6570_level_2::UriTemplate;

let template = UriTemplate::new("https://example.com/{resource}/{+id}{#field}")?;
let variables: Vec<&str> = template.variables().collect();
assert_eq!(variables, vec!["resource", "id", "field"]);

#[must_use]pub fn expand(&self, variables: &HashMap<&str, &str>) -> String[src]

Returns a copy of the URI template string, with all expressions expanded based on the given variable map.

Examples

use rfc6570_level_2::UriTemplate;
use std::collections::HashMap;

let template = UriTemplate::new("https://example.com/{resource}/{+id}{#field}")?;
let var_map = [
    ("resource", "user"),
    ("id", "5"),
    ("field", "email"),
].iter().cloned().collect();
let uri = template.expand(&var_map);
assert_eq!(uri, "https://example.com/user/5#email");

Trait Implementations

impl Clone for UriTemplate[src]

impl Debug for UriTemplate[src]

impl Eq for UriTemplate[src]

impl Hash for UriTemplate[src]

impl Ord for UriTemplate[src]

impl PartialEq<UriTemplate> for UriTemplate[src]

impl PartialOrd<UriTemplate> for UriTemplate[src]

impl StructuralEq for UriTemplate[src]

impl StructuralPartialEq for UriTemplate[src]

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> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

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

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

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T> TryConv for T

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.