Skip to main content

Crate async_tempfile

Crate async_tempfile 

Source
Expand description

§async-tempfile

Provides the TempFile struct, an asynchronous wrapper based on tokio::fs for temporary files that will be automatically deleted when the last reference to the struct is dropped.

use async_tempfile::TempFile;

#[tokio::main]
async fn main() {
    let parent = TempFile::new().await.unwrap();

    // The cloned reference will not delete the file when dropped.
    {
        let nested = parent.open_rw().await.unwrap();
        assert_eq!(nested.file_path(), parent.file_path());
        assert!(nested.file_path().is_file());
    }

    // The file still exists; it will be deleted when `parent` is dropped.
    assert!(parent.file_path().is_file());
}

§Features

  • uuid - Enables UUID-based random file name generation via the uuid crate and the new_with_uuid* group of methods. Not enabled by default; new/new_in work without it.

Structs§

PersistError
The error returned by crate::TempFile::persist and crate::TempDir::persist when the move to the target path fails.
TempDir
A named temporary directory that will be cleaned automatically after the last reference to it is dropped.
TempDirBuilder
A builder for configuring and creating a TempDir.
TempFile
A named temporary file that will be cleaned automatically after the last reference to it is dropped.
TempFileBuilder
A builder for configuring and creating a TempFile.

Enums§

Error
Ownership
Determines the ownership of a temporary file or directory.