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 1672865/week @ 2024-01-05 1666155/week @ 2024-01-12 1708954/week @ 2024-01-19 1704742/week @ 2024-01-26 1816634/week @ 2024-02-02 1833684/week @ 2024-02-09 1766605/week @ 2024-02-16 1970256/week @ 2024-02-23 1941986/week @ 2024-03-01 1810677/week @ 2024-03-08 1810388/week @ 2024-03-15 1799232/week @ 2024-03-22 1720962/week @ 2024-03-29 1759109/week @ 2024-04-05 1771338/week @ 2024-04-12 1467372/week @ 2024-04-19

7,041,339 downloads per month
Used in 13,983 crates (4,542 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

~2–11MB
~132K SLoC