Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Rust

Idiom #138 Create temp file

Create a new temporary file on the filesystem.

use tempdir::TempDir;
use std::fs::File;
let temp_dir = TempDir::new("prefix")?;
let temp_file = File::open(temp_dir.path().join("file_name"))?;

TempDir deletes the directory and its contents when it is dropped.
#include <stdlib.h>
const char tmpl[] = "XXXXXX.tmp";
int fd = mkstemp(tmpl);

Template must contain six X characters that will be modified by mkstemp

New implementation...
< >
programming-idioms.org