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 1616064/week @ 2024-01-03 1658023/week @ 2024-01-10 1730691/week @ 2024-01-17 1675596/week @ 2024-01-24 1798723/week @ 2024-01-31 1818822/week @ 2024-02-07 1783689/week @ 2024-02-14 1922123/week @ 2024-02-21 1954642/week @ 2024-02-28 1863207/week @ 2024-03-06 1783999/week @ 2024-03-13 1815083/week @ 2024-03-20 1702135/week @ 2024-03-27 1791137/week @ 2024-04-03 1776465/week @ 2024-04-10 1443806/week @ 2024-04-17

7,045,588 downloads per month
Used in 13,958 crates (4,538 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–13MB
~140K SLoC