use std::fmt::Write;
pub trait Template {
fn to_template(&self) -> String;
}
macro_rules! impl_template {
($struct_name:ident { $($field_name:ident),* }) => {
impl Template for $struct_name<'_> {
fn to_template(&self) -> String {
let mut result = String::new();
$(
let _ = write!(result, "{}: {}\n", stringify!($field_name), &self.$field_name);
)*
result
}
}
};
}
pub struct FormatObject<'f> {
pub percentage: &'f f32,
pub state: &'f str,
pub energy_rate: &'f f32,
}
impl_template!(FormatObject {
percentage,
state,
energy_rate
});