Bug: 204476125

Clone this repo:
  1. 2e20d6c Migrate 25 crates to monorepo. am: 8f07ec38b6 by James Farrell · 5 months ago main master
  2. 8f07ec3 Migrate 25 crates to monorepo. by James Farrell · 5 months ago
  3. a39da6b Update Android.bp by running cargo_embargo am: ee232a32ac by James Farrell · 6 months ago
  4. ee232a3 Update Android.bp by running cargo_embargo by James Farrell · 6 months ago
  5. f6139d5 Update Android.bp by running cargo_embargo am: 575de37192 am: 9370ced250 by James Farrell · 8 months ago android15-tests-dev

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.40.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);
}