6 releases (breaking)

0.6.0 Jun 30, 2024
0.5.0 Dec 6, 2023
0.4.0 Jun 16, 2023
0.3.0 Jun 12, 2023
0.1.0 Oct 22, 2022

#142 in Filesystem

Download history 4934/week @ 2024-06-13 5527/week @ 2024-06-20 5580/week @ 2024-06-27 4314/week @ 2024-07-04 5042/week @ 2024-07-11 5335/week @ 2024-07-18 5913/week @ 2024-07-25 7040/week @ 2024-08-01 6863/week @ 2024-08-08 5866/week @ 2024-08-15 7205/week @ 2024-08-22 5646/week @ 2024-08-29 5806/week @ 2024-09-05 5831/week @ 2024-09-12 7160/week @ 2024-09-19 7919/week @ 2024-09-26

27,938 downloads per month
Used in 5 crates

MIT license

39KB
496 lines

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());
}

Dependencies

~2–7.5MB
~48K SLoC