Struct tmp_env::TmpDir[][src]

pub struct TmpDir(_);
Expand description

A helper datastructure for ensuring that we delete the tmp dir created before end of the current scope.

Methods from Deref<Target = PathBuf>

Coerces to a Path slice.

Examples

use std::path::{Path, PathBuf};

let p = PathBuf::from("/test");
assert_eq!(Path::new("/test"), p.as_path());

Extends self with path.

If path is absolute, it replaces the current path.

On Windows:

  • if path has a root but no prefix (e.g., \windows), it replaces everything except for the prefix (if any) of self.
  • if path has a prefix but no root, it replaces self.

Examples

Pushing a relative path extends the existing path:

use std::path::PathBuf;

let mut path = PathBuf::from("/tmp");
path.push("file.bk");
assert_eq!(path, PathBuf::from("/tmp/file.bk"));

Pushing an absolute path replaces the existing path:

use std::path::PathBuf;

let mut path = PathBuf::from("/tmp");
path.push("/etc");
assert_eq!(path, PathBuf::from("/etc"));

Truncates self to self.parent.

Returns false and does nothing if self.parent is None. Otherwise, returns true.

Examples

use std::path::{Path, PathBuf};

let mut p = PathBuf::from("/spirited/away.rs");

p.pop();
assert_eq!(Path::new("/spirited"), p);
p.pop();
assert_eq!(Path::new("/"), p);

Updates self.file_name to file_name.

If self.file_name was None, this is equivalent to pushing file_name.

Otherwise it is equivalent to calling pop and then pushing file_name. The new path will be a sibling of the original path. (That is, it will have the same parent.)

Examples

use std::path::PathBuf;

let mut buf = PathBuf::from("/");
assert!(buf.file_name() == None);
buf.set_file_name("bar");
assert!(buf == PathBuf::from("/bar"));
assert!(buf.file_name().is_some());
buf.set_file_name("baz.txt");
assert!(buf == PathBuf::from("/baz.txt"));

Updates self.extension to extension.

Returns false and does nothing if self.file_name is None, returns true and updates the extension otherwise.

If self.extension is None, the extension is added; otherwise it is replaced.

Examples

use std::path::{Path, PathBuf};

let mut p = PathBuf::from("/feel/the");

p.set_extension("force");
assert_eq!(Path::new("/feel/the.force"), p.as_path());

p.set_extension("dark_side");
assert_eq!(Path::new("/feel/the.dark_side"), p.as_path());

Invokes capacity on the underlying instance of OsString.

Invokes clear on the underlying instance of OsString.

Invokes reserve on the underlying instance of OsString.

Invokes reserve_exact on the underlying instance of OsString.

Invokes shrink_to_fit on the underlying instance of OsString.

🔬 This is a nightly-only experimental API. (shrink_to)

Invokes shrink_to on the underlying instance of OsString.

Trait Implementations

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.