pub struct TemplateEngine { /* private fields */ }Expand description
Template engine for generating files from templates
Implementations§
Source§impl TemplateEngine
impl TemplateEngine
Sourcepub fn render(
&self,
template_path: &str,
variables: &HashMap<&str, &str>,
) -> Result<String>
pub fn render( &self, template_path: &str, variables: &HashMap<&str, &str>, ) -> Result<String>
Render a template with variables
§Arguments
template_path- Path to template file relative to template_dir (e.g., “drivers/sensor.rs.template”)variables- HashMap of variable names to values
§Returns
Rendered template content as String
§Example
ⓘ
let mut vars = HashMap::new();
vars.insert("name", "camera_driver");
vars.insert("PascalName", "CameraDriver");
let engine = TemplateEngine::default();
let rendered = engine.render("drivers/sensor.rs.template", &vars)?;Sourcepub async fn render_to_file(
&self,
template_path: &str,
output_path: impl AsRef<Path>,
variables: &HashMap<&str, &str>,
) -> Result<()>
pub async fn render_to_file( &self, template_path: &str, output_path: impl AsRef<Path>, variables: &HashMap<&str, &str>, ) -> Result<()>
Render a template and write it to a file
§Arguments
template_path- Path to template file relative to template_diroutput_path- Destination file pathvariables- HashMap of variable names to values
Sourcepub fn template_exists(&self, template_path: &str) -> bool
pub fn template_exists(&self, template_path: &str) -> bool
Check if a template exists
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TemplateEngine
impl RefUnwindSafe for TemplateEngine
impl Send for TemplateEngine
impl Sync for TemplateEngine
impl Unpin for TemplateEngine
impl UnsafeUnpin for TemplateEngine
impl UnwindSafe for TemplateEngine
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more