commit | 8c331c819a041c1fcd6b3e08041a53469d043f0d | [log] [tgz] |
---|---|---|
author | Matthew Maurer <mmaurer@google.com> | Tue Mar 07 17:24:57 2023 -0800 |
committer | Matthew Maurer <mmaurer@google.com> | Tue Mar 07 17:24:57 2023 -0800 |
tree | 95cb488307c04b8942d85975d0676fb4c1e1ce04 | |
parent | 4578b5b3b34d2dc74034747ceda1ebffa9c9acc5 [diff] |
Make tempfile available to product and vendor Bug: 270690570 Test: mma in external/rust/crates Change-Id: I94f72fca8edb89156197b154c377a601b454ef2d
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).
Minimum required Rust version: 1.40.0
Add this to your Cargo.toml
:
[dependencies] tempfile = "3"
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); }