async-tempfile

Crates.ioasync-tempfile
lib.rsasync-tempfile
version0.6.0
sourcesrc
created_at2022-10-22 00:11:47.088098
updated_at2024-06-30 11:20:01.439051
descriptionAutomatically deleted async I/O temporary files.
homepage
repositoryhttps://github.com/sunsided/async-tempfile-rs
max_upload_size
id694035
size47,018
Markus Mayer (sunsided)

documentation

https://docs.rs/async-tempfile

README

async-tempfile

Crates.io Crates.io GitHub Workflow Status docs.rs codecov

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());
}
Commit count: 74

cargo fmt