FileGenerator

Struct FileGenerator 

Source
pub struct FileGenerator { /* private fields */ }
Expand description

Handles creation of files and directories on the filesystem

FileGenerator provides safe file operations with configurable overwrite behavior and proper error handling.

Implementations§

Source§

impl FileGenerator

Source

pub fn new() -> Self

Create a new FileGenerator with default settings (no force overwrite)

Source

pub fn with_force_overwrite(self, force: bool) -> Self

Configure whether existing files should be overwritten

When force_overwrite is true, existing files will be replaced. When false, attempting to create existing files will return an error.

Source

pub fn create_directory<P: AsRef<Path>>(&self, path: P) -> Result<()>

Create a directory and all necessary parent directories

This method:

  • Creates the directory and any missing parent directories
  • Handles the case where the path already exists as a directory
  • Returns an error if the path exists but is not a directory
Source

pub fn create_file<P: AsRef<Path>>(&self, path: P, content: &str) -> Result<()>

Create a file with the specified content

This method:

  • Checks for existing files and respects the force_overwrite setting
  • Creates parent directories if they don’t exist
  • Writes the content to the file (overwrites if file exists and force is true)

Trait Implementations§

Source§

impl Default for FileGenerator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.