Template

Struct Template 

Source
pub struct Template { /* private fields */ }

Implementations§

Source§

impl Template

Source

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

Source

pub fn render(&self, vals: &HashMap<&str, &str>) -> String


let template = Template::new("Hi, my name is {{name}} and I'm a {{lang}} developer.");

let mut args = HashMap::new();
args.insert("name", "Michael");
args.insert("lang", "Rust");
let s = template.render(&args);

assert_eq!(s, "Hi, my name is Michael and I'm a Rust developer.");

let mut args1 = HashMap::new();
args1.insert("name", "Vader");
args1.insert("lang", "Dart");
let s2 = template.render(&args1);

assert_eq!(s2, "Hi, my name is Vader and I'm a Dart developer.");
Source

pub fn render_named(&self, vals: &HashMap<&str, &str>) -> String

See render() for examples.

Source

pub fn render_positional(&self, vals: &[&str]) -> String

let template = Template::new("Hi, my name is {{}} and I'm a {{}} developer.");

let args = vec!["Michael", "Rust"];
let s = template.render_positional(&args);
assert_eq!(s, "Hi, my name is Michael and I'm a Rust developer.");

let args1 = vec!["Vader", "Dart"];
let s2 = template.render_positional(&args1);
assert_eq!(s2, "Hi, my name is Vader and I'm a Dart developer.");

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.