pub struct FileTreeGenerator { /* private fields */ }Expand description
File tree generator for creating directory structures from templates
Takes a FileTreeTemplate and a TemplateContext, then generates the
corresponding file tree in the filesystem with variable substitution.
§Examples
use ggen_core::templates::generator::FileTreeGenerator;
use ggen_core::templates::{FileTreeTemplate, TemplateContext};
use ggen_core::templates::format::TemplateFormat;
use std::path::Path;
let format = TemplateFormat::new("my-template");
let template = FileTreeTemplate::new(format);
let context = TemplateContext::new();
let mut generator = FileTreeGenerator::new(template, context, Path::new("output"));
let result = generator.generate()?;Implementations§
Source§impl FileTreeGenerator
impl FileTreeGenerator
Sourcepub fn new<P: AsRef<Path>>(
template: FileTreeTemplate,
context: TemplateContext,
base_dir: P,
) -> Self
pub fn new<P: AsRef<Path>>( template: FileTreeTemplate, context: TemplateContext, base_dir: P, ) -> Self
Create a new file tree generator
§Arguments
template- The file tree template to generate fromcontext- Variable context for template renderingbase_dir- Base directory where files will be generated
§Examples
use ggen_core::templates::generator::FileTreeGenerator;
use ggen_core::templates::{FileTreeTemplate, TemplateContext};
use ggen_core::templates::format::TemplateFormat;
use std::path::Path;
let format = TemplateFormat::new("my-template");
let template = FileTreeTemplate::new(format);
let context = TemplateContext::new();
let generator = FileTreeGenerator::new(template, context, Path::new("output"));Sourcepub fn generate(&mut self) -> Result<GenerationResult>
pub fn generate(&mut self) -> Result<GenerationResult>
Generate the file tree from the template
This method:
- Validates that all required variables are provided
- Applies default values for optional variables
- Processes each node in the template tree
- Creates directories and files with rendered content
§Errors
Returns an error if:
- Required variables are missing
- Template rendering fails
- File system operations fail
§Examples
use ggen_core::templates::generator::FileTreeGenerator;
use ggen_core::templates::{FileTreeTemplate, TemplateContext};
use ggen_core::templates::format::{TemplateFormat, FileTreeNode};
use std::path::Path;
let mut format = TemplateFormat::new("my-template");
format.add_node(FileTreeNode::directory("src"));
let template = FileTreeTemplate::new(format);
let context = TemplateContext::new();
let mut generator = FileTreeGenerator::new(template, context, Path::new("output"));
let result = generator.generate()?;
println!("Generated {} directories", result.directories().len());Sourcepub fn template(&self) -> &FileTreeTemplate
pub fn template(&self) -> &FileTreeTemplate
Get the template being used
Sourcepub fn context(&self) -> &TemplateContext
pub fn context(&self) -> &TemplateContext
Get the context being used
Auto Trait Implementations§
impl Freeze for FileTreeGenerator
impl RefUnwindSafe for FileTreeGenerator
impl Send for FileTreeGenerator
impl Sync for FileTreeGenerator
impl Unpin for FileTreeGenerator
impl UnwindSafe for FileTreeGenerator
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 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>
Wrap the input message
T in a tonic::Request