pub struct TemplateManager { /* private fields */ }Expand description
Template manager that handles on-demand creation of templates from embedded resources
Implementations§
Source§impl TemplateManager
impl TemplateManager
Sourcepub fn new<P: Into<PathBuf>>(templates_dir: P) -> Self
pub fn new<P: Into<PathBuf>>(templates_dir: P) -> Self
Create a new template manager with a custom templates directory
Sourcepub fn ensure_templates_dir(&self) -> Result<(), TemplateManagerError>
pub fn ensure_templates_dir(&self) -> Result<(), TemplateManagerError>
Create the templates directory if it doesn’t exist
§Errors
Returns an error if the directory creation fails due to permissions or filesystem issues.
Sourcepub fn reset_templates_dir(&self) -> Result<(), TemplateManagerError>
pub fn reset_templates_dir(&self) -> Result<(), TemplateManagerError>
Clean and prepare the templates directory to ensure fresh embedded templates
This method combines clean_templates_dir() and ensure_templates_dir() to provide
a clean state for template operations. It’s particularly useful in testing and
development environments where you want to ensure fresh templates from embedded resources.
§Errors
Returns an error if either directory cleaning or creation fails due to permissions or filesystem issues.
Sourcepub fn get_template_path(
&self,
relative_path: &str,
) -> Result<PathBuf, TemplateManagerError>
pub fn get_template_path( &self, relative_path: &str, ) -> Result<PathBuf, TemplateManagerError>
Get the path to a template file, creating it from embedded resources if it doesn’t exist
§Errors
Returns an error if:
- The template is not found in embedded resources
- The embedded template contains invalid UTF-8
- File system operations fail (directory creation or file writing)
Sourcepub fn templates_dir(&self) -> &Path
pub fn templates_dir(&self) -> &Path
Get the templates directory path
Sourcepub fn clean_templates_dir(&self) -> Result<(), TemplateManagerError>
pub fn clean_templates_dir(&self) -> Result<(), TemplateManagerError>
Clean the templates directory by removing all files and subdirectories
This is useful for development/testing to ensure fresh templates are used from embedded resources.
§Errors
Returns an error if the directory removal fails due to permissions or filesystem issues.
Auto Trait Implementations§
impl Freeze for TemplateManager
impl RefUnwindSafe for TemplateManager
impl Send for TemplateManager
impl Sync for TemplateManager
impl Unpin for TemplateManager
impl UnsafeUnpin for TemplateManager
impl UnwindSafe for TemplateManager
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
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> ⓘ
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> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request