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

#120 in Asynchronous

Download history 11725/week @ 2024-10-20 12107/week @ 2024-10-27 13140/week @ 2024-11-03 11547/week @ 2024-11-10 11597/week @ 2024-11-17 7543/week @ 2024-11-24 17816/week @ 2024-12-01 10920/week @ 2024-12-08 10051/week @ 2024-12-15 2505/week @ 2024-12-22 5650/week @ 2024-12-29 11059/week @ 2025-01-05 11172/week @ 2025-01-12 10100/week @ 2025-01-19 21875/week @ 2025-01-26 22906/week @ 2025-02-02

66,472 downloads per month
Used in 10 crates (7 directly)

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–8MB
~48K SLoC