pub fn tempdir_in<P: AsRef<Utf8Path>>(dir: P) -> Result<Utf8TempDir>
Expand description

Create a new temporary directory in a specific directory.

The tempdir_in function creates a directory in the specified directory and returns a Utf8TempDir. The directory will be automatically deleted when the Utf8TempDir’s destructor is run.

Resource Leaking

See the resource leaking docs on Utf8TempDir.

Errors

If the directory can not be created, Err is returned.

Examples

use camino_tempfile::tempdir_in;
use std::fs::File;
use std::io::{self, Write};

// Create a directory inside of the current directory.
let dir = tempdir_in(".")?;

let file_path = dir.path().join("my-temporary-note.txt");
let mut file = File::create(file_path)?;
writeln!(file, "Brian was here. Briefly.")?;

// `tmp_dir` goes out of scope, the directory as well as
// `tmp_file` will be deleted here.
drop(file);
dir.close()?;