pub struct Template {
pub src: String,
pub matches: Vec<(usize, usize)>,
pub names: HashSet<String>,
}
Fields§
§src: String
§matches: Vec<(usize, usize)>
§names: HashSet<String>
Implementations§
Source§impl Template
impl Template
pub fn new(template: &str) -> Self
Sourcepub fn render(&self, vals: &HashMap<String, String>) -> String
pub fn render(&self, vals: &HashMap<String, String>) -> String
§Examples
use std::collections::HashMap;
use requestr_core::Template;
let template = Template::new("Hi, my name is {{ name }} and I'm a {{ lang }} developer.");
let mut args: HashMap<String, String> = HashMap::new();
args.insert("name".to_string(), "Stefan".to_string());
args.insert("lang".to_string(), "Scala".to_string());
let s = template.render(&args);
assert_eq!(s, "Hi, my name is Stefan and I'm a Scala developer.");
use std::collections::HashMap;
use requestr_core::Template;
let template = Template::new("Hi, my name is {{ name }} and I'm a {{lang}} developer.");
let mut args: HashMap<String, String> = HashMap::new();
args.insert("name".to_string(), "undefined".to_string());
args.insert("lang".to_string(), "JavaScript".to_string());
let s = template.render(&args);
assert_eq!(s, "Hi, my name is undefined and I'm a JavaScript developer.");
Trait Implementations§
impl StructuralPartialEq for Template
Auto Trait Implementations§
impl Freeze for Template
impl RefUnwindSafe for Template
impl Send for Template
impl Sync for Template
impl Unpin for Template
impl UnwindSafe for Template
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more