pub struct File { /* private fields */ }Expand description
A Data Transfer Object (DTO) representing template file metadata for the deployment system.
The File struct encapsulates metadata about template files without being responsible
for template resolution or rendering. It serves as a structured representation of
template information that can be passed between components in the deployment pipeline.
§Purpose
This DTO is designed to:
- Parse and store template file metadata (path, format, engine type)
- Provide a standardized representation of template information
- Enable validation of template file structure and format
- Facilitate template processing by other components
Note: This struct does NOT handle template rendering or variable resolution. Those responsibilities belong to dedicated template engine components.
§Template Engine Detection
The engine is determined by the file extension pattern:
- Files ending with
.teraare processed as Tera templates - All other files are treated as static files
§Format Detection
For Tera templates (.ext.tera), the inner extension determines the output format.
For static files, the extension directly determines the format.
Supported formats: yml/yaml, toml, tf, tera
§Examples
// Create DTO for a static YAML file
let static_file = File::new("config/app.yml", "key: value".to_string())?;
assert_eq!(static_file.engine(), &torrust_tracker_deployer_lib::domain::template::file::Engine::Static);
// Create DTO for a Tera template that outputs YAML
let template_file = File::new("templates/inventory.yml.tera", "host: {{ vm_ip }}".to_string())?;
assert_eq!(template_file.engine(), &torrust_tracker_deployer_lib::domain::template::file::Engine::Tera);
assert_eq!(template_file.inner_format(), Some(&torrust_tracker_deployer_lib::domain::template::file::Format::Yml));Implementations§
Source§impl File
impl File
Sourcepub fn new(path: &str, content: String) -> Result<File, Error>
pub fn new(path: &str, content: String) -> Result<File, Error>
Creates a new template file with metadata extracted from the path
§Arguments
path- Full path to the template file (e.g., “templates/ansible/inventory.yml.tera”)content- The content of the template file as a string
§Errors
Returns an error if:
- The file path does not contain a file extension
- The file extension is not recognized
- A Tera template file (.tera) does not have a valid inner extension to determine output format
§Examples
let file = File::new("templates/ansible/inventory.yml.tera", "content here".to_string())?;
// This creates a Tera template with yml inner format
let static_file = File::new("templates/ansible/wait-cloud-init.yml", "---\nkey: value".to_string())?;
// This creates a static yml filepub fn engine(&self) -> &Engine
pub fn path(&self) -> &str
pub fn filename(&self) -> &str
pub fn format(&self) -> &Format
pub fn extension(&self) -> &Extension
pub fn inner_format(&self) -> Option<&Format>
pub fn inner_extension(&self) -> Option<&Extension>
pub fn content(&self) -> &str
Trait Implementations§
Auto Trait Implementations§
impl Freeze for File
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnsafeUnpin for File
impl UnwindSafe for File
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