7 releases (breaking)

0.7.0 Feb 22, 2025
0.6.0 Jun 30, 2024
0.5.0 Dec 6, 2023
0.4.0 Jun 16, 2023
0.1.0 Oct 22, 2022

#105 in Asynchronous

Download history 11899/week @ 2024-11-16 7619/week @ 2024-11-23 17383/week @ 2024-11-30 11147/week @ 2024-12-07 10176/week @ 2024-12-14 2655/week @ 2024-12-21 5420/week @ 2024-12-28 11045/week @ 2025-01-04 11109/week @ 2025-01-11 9528/week @ 2025-01-18 21030/week @ 2025-01-25 24354/week @ 2025-02-01 20100/week @ 2025-02-08 19651/week @ 2025-02-15 37279/week @ 2025-02-22 31965/week @ 2025-03-01

113,185 downloads per month
Used in 10 crates (7 directly)

MIT license

41KB
502 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