nix::unistd

Function mkdtemp

source
pub fn mkdtemp<P: ?Sized + NixPath>(template: &P) -> Result<PathBuf>
Expand description

Creates a directory which persists even after process termination

  • template: a path whose rightmost characters contain some number of X, e.g. /tmp/tmpdir_XXXXXX
  • returns: filename

Err is returned either if no temporary filename could be created or the template had insufficient X

See also mkstemp(2)

use nix::unistd;

match unistd::mkdtemp("/tmp/tempdir_XXXXXX") {
    Ok(_path) => {
        // do something with directory
    }
    Err(e) => panic!("mkdtemp failed: {}", e)
};