pub struct TemplateString<T> { /* private fields */ }Expand description
A type-safe template string that can be formatted with values of type T.
Template strings contain placeholders in the form {field_name} that correspond
to fields in type T. The template is validated at parse time to ensure all
placeholders are valid.
§Examples
#[derive(TemplateParams)]
struct Person {
name: String,
title: String,
}
let template: TemplateString<Person> = "Dear {title} {name}".parse().unwrap();
let person = Person {
name: "Smith".to_string(),
title: "Dr.".to_string(),
};
assert_eq!(template.format(&person), "Dear Dr. Smith");Implementations§
Source§impl<T: TemplateParams> TemplateString<T>
impl<T: TemplateParams> TemplateString<T>
Sourcepub fn format(&self, params: &T) -> String
pub fn format(&self, params: &T) -> String
Format the template with the provided parameter values.
§Examples
#[derive(TemplateParams)]
struct Data {
x: i32,
y: i32,
}
let template: TemplateString<Data> = "Point: ({x}, {y})".parse().unwrap();
let data = Data { x: 10, y: 20 };
assert_eq!(template.format(&data), "Point: (10, 20)");Trait Implementations§
Source§impl<T> Clone for TemplateString<T>
impl<T> Clone for TemplateString<T>
Source§impl<T> Debug for TemplateString<T>
impl<T> Debug for TemplateString<T>
Source§impl<T: TemplateParams> Display for TemplateString<T>
impl<T: TemplateParams> Display for TemplateString<T>
Source§impl<T: TemplateParams> FromStr for TemplateString<T>
impl<T: TemplateParams> FromStr for TemplateString<T>
Source§impl<T> PartialEq for TemplateString<T>
impl<T> PartialEq for TemplateString<T>
Auto Trait Implementations§
impl<T> Freeze for TemplateString<T>
impl<T> RefUnwindSafe for TemplateString<T>where
T: RefUnwindSafe,
impl<T> Send for TemplateString<T>where
T: Send,
impl<T> Sync for TemplateString<T>where
T: Sync,
impl<T> Unpin for TemplateString<T>where
T: Unpin,
impl<T> UnwindSafe for TemplateString<T>where
T: UnwindSafe,
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