pub struct FileTreeNode {
pub node_type: NodeType,
pub name: String,
pub children: Vec<FileTreeNode>,
pub content: Option<String>,
pub template: Option<String>,
pub mode: Option<u32>,
}Expand description
A node in the file tree template
Represents either a file or directory in the generated file tree. Directory nodes can contain children, while file nodes contain content or reference template files.
§Examples
§Creating a directory node
use ggen_core::templates::format::FileTreeNode;
let dir = FileTreeNode::directory("src");
assert_eq!(dir.name, "src");§Creating a file node with content
use ggen_core::templates::format::FileTreeNode;
let file = FileTreeNode::file_with_content("main.rs", "fn main() {}");
assert_eq!(file.name, "main.rs");
assert_eq!(file.content, Some("fn main() {}".to_string()));Fields§
§node_type: NodeTypeType of node (file or directory)
name: StringName of the file or directory (may contain template variables)
children: Vec<FileTreeNode>Children nodes (for directories)
content: Option<String>Inline content (for files)
template: Option<String>Template file reference (for files)
mode: Option<u32>File permissions (Unix mode)
Implementations§
Source§impl FileTreeNode
impl FileTreeNode
Sourcepub fn directory(name: impl Into<String>) -> Self
pub fn directory(name: impl Into<String>) -> Self
Create a new directory node
Creates a directory node with no children. Children can be added
using add_child().
§Arguments
name- Directory name (may contain template variables like{{ name }})
§Returns
A new FileTreeNode with NodeType::Directory.
§Examples
use ggen_core::templates::format::{FileTreeNode, NodeType};
let dir = FileTreeNode::directory("src");
assert_eq!(dir.node_type, NodeType::Directory);
assert_eq!(dir.name, "src");
assert!(dir.children.is_empty());Sourcepub fn file_with_content(
name: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn file_with_content( name: impl Into<String>, content: impl Into<String>, ) -> Self
Create a new file node with inline content
Creates a file node with inline content that will be written directly to the generated file. The content may contain template variables.
§Arguments
name- File name (may contain template variables)content- File content (may contain template variables)
§Returns
A new FileTreeNode with NodeType::File and inline content.
§Examples
use ggen_core::templates::format::{FileTreeNode, NodeType};
let file = FileTreeNode::file_with_content("main.rs", "fn main() {}");
assert_eq!(file.node_type, NodeType::File);
assert_eq!(file.name, "main.rs");
assert_eq!(file.content, Some("fn main() {}".to_string()));Sourcepub fn file_with_template(
name: impl Into<String>,
template: impl Into<String>,
) -> Self
pub fn file_with_template( name: impl Into<String>, template: impl Into<String>, ) -> Self
Create a new file node with template reference
Creates a file node that references an external template file. The template will be loaded and rendered during generation.
§Arguments
name- File name (may contain template variables)template- Path to template file (relative to template base directory)
§Returns
A new FileTreeNode with NodeType::File and a template reference.
§Examples
use ggen_core::templates::format::{FileTreeNode, NodeType};
let file = FileTreeNode::file_with_template("lib.rs", "templates/lib.rs.tera");
assert_eq!(file.node_type, NodeType::File);
assert_eq!(file.name, "lib.rs");
assert_eq!(file.template, Some("templates/lib.rs.tera".to_string()));Sourcepub fn add_child(&mut self, child: FileTreeNode) -> &mut Self
pub fn add_child(&mut self, child: FileTreeNode) -> &mut Self
Add a child node (for directories)
Adds a child node to this directory. Only valid for directory nodes.
Returns &mut Self for method chaining.
§Arguments
child- Child node to add
§Returns
&mut Self for method chaining.
§Examples
use ggen_core::templates::format::FileTreeNode;
let mut dir = FileTreeNode::directory("src");
dir.add_child(FileTreeNode::file_with_content("main.rs", "fn main() {}"));
assert_eq!(dir.children.len(), 1);
assert_eq!(dir.children[0].name, "main.rs");Sourcepub fn with_mode(self, mode: u32) -> Self
pub fn with_mode(self, mode: u32) -> Self
Set file permissions
Sets Unix file permissions (mode) for this file node. Only valid for file nodes.
Returns Self for method chaining.
§Arguments
mode- Unix file mode (e.g.,0o755for executable)
§Returns
Self for method chaining.
§Examples
use ggen_core::templates::format::FileTreeNode;
let file = FileTreeNode::file_with_content("script.sh", "#!/bin/bash")
.with_mode(0o755);
assert_eq!(file.mode, Some(0o755));Trait Implementations§
Source§impl Clone for FileTreeNode
impl Clone for FileTreeNode
Source§fn clone(&self) -> FileTreeNode
fn clone(&self) -> FileTreeNode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FileTreeNode
impl Debug for FileTreeNode
Source§impl<'de> Deserialize<'de> for FileTreeNode
impl<'de> Deserialize<'de> for FileTreeNode
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for FileTreeNode
impl RefUnwindSafe for FileTreeNode
impl Send for FileTreeNode
impl Sync for FileTreeNode
impl Unpin for FileTreeNode
impl UnwindSafe for FileTreeNode
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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