Skip to main content

WritableSystem

Trait WritableSystem 

Source
pub trait WritableSystem: System {
    // Required methods
    fn create_new_file(&self, path: &SystemPath) -> Result<()>;
    fn write_file_bytes(&self, path: &SystemPath, content: &[u8]) -> Result<()>;
    fn create_directory_all(&self, path: &SystemPath) -> Result<()>;
    fn dyn_clone(&self) -> Box<dyn WritableSystem>;

    // Provided methods
    fn write_file(&self, path: &SystemPath, content: &str) -> Result<()> { ... }
    fn get_or_cache(
        &self,
        path: &SystemPath,
        read_contents: &dyn Fn() -> Result<String>,
    ) -> Result<Option<SystemPathBuf>> { ... }
}
Expand description

System trait for non-readonly systems.

Required Methods§

Source

fn create_new_file(&self, path: &SystemPath) -> Result<()>

Creates a file at the given path.

Returns an error if the file already exists.

Source

fn write_file_bytes(&self, path: &SystemPath, content: &[u8]) -> Result<()>

Writes the given content to the file at the given path.

Source

fn create_directory_all(&self, path: &SystemPath) -> Result<()>

Creates a directory at path as well as any intermediate directories.

Source

fn dyn_clone(&self) -> Box<dyn WritableSystem>

Provided Methods§

Source

fn write_file(&self, path: &SystemPath, content: &str) -> Result<()>

Writes the given content to the file at the given path.

Source

fn get_or_cache( &self, path: &SystemPath, read_contents: &dyn Fn() -> Result<String>, ) -> Result<Option<SystemPathBuf>>

Reads the provided file from the system cache, or creates the file if necessary.

Returns Ok(None) if the system does not expose a suitable cache directory.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§