pub struct Template<'t> { /* private fields */ }
Expand description

The Template type is the basis for most simple tasks. Parsing and expansion are both template functions.

Implementations§

source§

impl<'t> Template<'t>

source

pub const fn expand<'e>(&'e self, values: &'e Values) -> Expansion<'e, 't>

Creates a new Expansion using the given Values, which may then be rendered using the to_string function provided by the Display trait.

let template = Template::parse("hello/{name}!").unwrap();
let values = Values::default().add("name", Value::item("world"));

assert_eq!("hello/world!", template.expand(&values).to_string());
source

pub fn parse(raw: &'t str) -> Result<Self, ParseError>

Parses a string representing a potential template, and returns a new template instance if valid. See https://datatracker.ietf.org/doc/html/rfc6570 for the grammar of a valid URI Template. uri-template-system supports all operators and modifiers up-to and including Level 4.

let template = Template::parse("my/valid/{template}");

assert!(template.is_ok());

Trait Implementations§

source§

impl<'t> Debug for Template<'t>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'t> PartialEq<Template<'t>> for Template<'t>

source§

fn eq(&self, other: &Template<'t>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'t> Eq for Template<'t>

source§

impl<'t> StructuralEq for Template<'t>

source§

impl<'t> StructuralPartialEq for Template<'t>

Auto Trait Implementations§

§

impl<'t> RefUnwindSafe for Template<'t>

§

impl<'t> Send for Template<'t>

§

impl<'t> Sync for Template<'t>

§

impl<'t> Unpin for Template<'t>

§

impl<'t> UnwindSafe for Template<'t>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.