Skip to main content

TempResourceFactory

Trait TempResourceFactory 

Source
pub trait TempResourceFactory:
    Debug
    + Send
    + Sync {
    // Required methods
    fn create_file(
        &self,
        owner: Arc<dyn FileSystem>,
        options: &TempFileOptions,
    ) -> FsResult<Box<dyn TempFile>>;
    fn create_dir(
        &self,
        owner: Arc<dyn FileSystem>,
        options: &TempDirOptions,
    ) -> FsResult<Box<dyn TempDir>>;

    // Provided method
    fn make_temp_path(
        &self,
        parent: Option<&FsPath>,
        prefix: &str,
        suffix: &str,
    ) -> FsResult<FsPath> { ... }
}
Expand description

Factory for filesystem-owned temporary resources.

Required Methods§

Source

fn create_file( &self, owner: Arc<dyn FileSystem>, options: &TempFileOptions, ) -> FsResult<Box<dyn TempFile>>

Creates a temporary file.

§Parameters
  • owner: Filesystem that will own the temporary file.
  • options: Temporary file creation options.
§Returns

Temporary file handle with cleanup responsibility.

§Errors

Returns crate::FsError when the temporary file cannot be created.

Source

fn create_dir( &self, owner: Arc<dyn FileSystem>, options: &TempDirOptions, ) -> FsResult<Box<dyn TempDir>>

Creates a temporary directory.

§Parameters
  • owner: Filesystem that will own the temporary directory.
  • options: Temporary directory creation options.
§Returns

Temporary directory handle with cleanup responsibility.

§Errors

Returns crate::FsError when the temporary directory cannot be created.

Provided Methods§

Source

fn make_temp_path( &self, parent: Option<&FsPath>, prefix: &str, suffix: &str, ) -> FsResult<FsPath>

Builds a temporary resource path using the common rs-fs naming format.

The default format is {prefix}{process_id}-{unix_epoch_nanos}-{counter}{suffix}. Implementations may use this helper to share the common format, or ignore it and apply provider-specific naming rules.

§Parameters
  • parent: Optional parent path. Root is used when absent.
  • prefix: Temporary name prefix.
  • suffix: Temporary name suffix.
§Returns

Generated temporary path.

§Errors

Returns crate::FsError when the generated path is invalid.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§