44 releases (stable)

3.10.1 Feb 26, 2024
3.9.0 Dec 28, 2023
3.8.1 Oct 26, 2023
3.7.0 Jul 20, 2023
0.5.1 May 22, 2015

#1 in Filesystem

Download history 1663374/week @ 2024-01-14 1670933/week @ 2024-01-21 1743204/week @ 2024-01-28 1843570/week @ 2024-02-04 1819857/week @ 2024-02-11 1809695/week @ 2024-02-18 1960474/week @ 2024-02-25 1922968/week @ 2024-03-03 1786426/week @ 2024-03-10 1804592/week @ 2024-03-17 1764607/week @ 2024-03-24 1767673/week @ 2024-03-31 1750632/week @ 2024-04-07 1769905/week @ 2024-04-14 1779621/week @ 2024-04-21 1573797/week @ 2024-04-28

6,994,244 downloads per month
Used in 14,115 crates (4,580 directly)

MIT/Apache

98KB
1K SLoC

tempfile

Crate Build Status

A secure, cross-platform, temporary file library for Rust. In addition to creating temporary files, this library also allows users to securely open multiple independent references to the same temporary file (useful for consumer/producer patterns and surprisingly difficult to implement securely).

Documentation

Usage

Minimum required Rust version: 1.63.0

Add this to your Cargo.toml:

[dependencies]
tempfile = "3"

Example

use std::fs::File;
use std::io::{Write, Read, Seek, SeekFrom};

fn main() {
    // Write
    let mut tmpfile: File = tempfile::tempfile().unwrap();
    write!(tmpfile, "Hello World!").unwrap();

    // Seek to start
    tmpfile.seek(SeekFrom::Start(0)).unwrap();

    // Read
    let mut buf = String::new();
    tmpfile.read_to_string(&mut buf).unwrap();
    assert_eq!("Hello World!", buf);
}

Dependencies

~1–12MB
~134K SLoC