android13/external/rust/crates/tempfile
liiir1985 7f62dcda9f initial 2024-06-22 20:45:49 +08:00
..
src initial 2024-06-22 20:45:49 +08:00
tests initial 2024-06-22 20:45:49 +08:00
Android.bp initial 2024-06-22 20:45:49 +08:00
Cargo.toml initial 2024-06-22 20:45:49 +08:00
LICENSE initial 2024-06-22 20:45:49 +08:00
LICENSE-APACHE initial 2024-06-22 20:45:49 +08:00
LICENSE-MIT initial 2024-06-22 20:45:49 +08:00
METADATA initial 2024-06-22 20:45:49 +08:00
MODULE_LICENSE_APACHE2 initial 2024-06-22 20:45:49 +08:00
NEWS initial 2024-06-22 20:45:49 +08:00
OWNERS initial 2024-06-22 20:45:49 +08:00
README.md initial 2024-06-22 20:45:49 +08:00
TEST_MAPPING initial 2024-06-22 20:45:49 +08:00
cargo2android.json initial 2024-06-22 20:45:49 +08:00

README.md

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