FileOperations

Trait FileOperations 

Source
pub trait FileOperations {
    // Provided methods
    fn read_file_with_context(path: impl AsRef<Path>) -> Result<String> { ... }
    fn write_file_with_context(
        path: impl AsRef<Path>,
        content: impl AsRef<str>,
    ) -> Result<()> { ... }
    fn create_dir_with_context(path: impl AsRef<Path>) -> Result<()> { ... }
    fn read_bytes_with_context(path: impl AsRef<Path>) -> Result<Vec<u8>> { ... }
    fn write_bytes_with_context(
        path: impl AsRef<Path>,
        content: impl AsRef<[u8]>,
    ) -> Result<()> { ... }
    fn copy_file_with_context(
        from: impl AsRef<Path>,
        to: impl AsRef<Path>,
    ) -> Result<u64> { ... }
    fn remove_file_with_context(path: impl AsRef<Path>) -> Result<()> { ... }
    fn remove_dir_all_with_context(path: impl AsRef<Path>) -> Result<()> { ... }
    fn check_exists_with_context(path: impl AsRef<Path>) -> Result<bool> { ... }
}
Expand description

Common file operations with consistent error handling

Provided Methods§

Source

fn read_file_with_context(path: impl AsRef<Path>) -> Result<String>

Read a file with appropriate error context

Source

fn write_file_with_context( path: impl AsRef<Path>, content: impl AsRef<str>, ) -> Result<()>

Write to a file with appropriate error context

Source

fn create_dir_with_context(path: impl AsRef<Path>) -> Result<()>

Create a directory with appropriate error context

Source

fn read_bytes_with_context(path: impl AsRef<Path>) -> Result<Vec<u8>>

Read a file as bytes with appropriate error context

Source

fn write_bytes_with_context( path: impl AsRef<Path>, content: impl AsRef<[u8]>, ) -> Result<()>

Write bytes to a file with appropriate error context

Source

fn copy_file_with_context( from: impl AsRef<Path>, to: impl AsRef<Path>, ) -> Result<u64>

Copy a file with appropriate error context

Source

fn remove_file_with_context(path: impl AsRef<Path>) -> Result<()>

Remove a file with appropriate error context

Source

fn remove_dir_all_with_context(path: impl AsRef<Path>) -> Result<()>

Remove a directory recursively with appropriate error context

Source

fn check_exists_with_context(path: impl AsRef<Path>) -> Result<bool>

Check if a path exists, returning error if checking fails

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§