• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1tempfile
2========
3
4[![Crate](https://img.shields.io/crates/v/tempfile.svg)](https://crates.io/crates/tempfile)
5[![Build Status](https://github.com/Stebalien/tempfile/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Stebalien/tempfile/actions/workflows/ci.yml?query=branch%3Amaster)
6
7A secure, cross-platform, temporary file library for Rust. In addition to creating
8temporary files, this library also allows users to securely open multiple
9independent references to the same temporary file (useful for consumer/producer
10patterns and surprisingly difficult to implement securely).
11
12[Documentation](https://docs.rs/tempfile/)
13
14Usage
15-----
16
17Minimum required Rust version: 1.40.0
18
19Add this to your `Cargo.toml`:
20```toml
21[dependencies]
22tempfile = "3"
23```
24
25Example
26-------
27
28```rust
29use std::fs::File;
30use std::io::{Write, Read, Seek, SeekFrom};
31
32fn main() {
33    // Write
34    let mut tmpfile: File = tempfile::tempfile().unwrap();
35    write!(tmpfile, "Hello World!").unwrap();
36
37    // Seek to start
38    tmpfile.seek(SeekFrom::Start(0)).unwrap();
39
40    // Read
41    let mut buf = String::new();
42    tmpfile.read_to_string(&mut buf).unwrap();
43    assert_eq!("Hello World!", buf);
44}
45```
46