vmm_sys_util::tempdir

Struct TempDir

source
pub struct TempDir { /* private fields */ }
Expand description

Wrapper over a temporary directory.

The directory will be maintained for the lifetime of the TempDir object.

Implementations§

source§

impl TempDir

source

pub fn new_with_prefix<P: AsRef<OsStr>>(prefix: P) -> Result<TempDir>

Creates a new temporary directory with prefix.

The directory will be removed when the object goes out of scope.

§Examples
let t = TempDir::new_with_prefix("/tmp/testdir").unwrap();
source

pub fn new_in(path: &Path) -> Result<TempDir>

Creates a new temporary directory with inside path.

The directory will be removed when the object goes out of scope.

§Examples
let t = TempDir::new_in(Path::new("/tmp/")).unwrap();
source

pub fn new() -> Result<TempDir>

Creates a new temporary directory with inside $TMPDIR if set, otherwise in /tmp.

The directory will be removed when the object goes out of scope.

§Examples
let t = TempDir::new().unwrap();
source

pub fn remove(&self) -> Result<()>

Removes the temporary directory.

Calling this is optional as when a TempDir object goes out of scope, the directory will be removed. Calling remove explicitly allows for better error handling.

§Errors

This function can only be called once per object. An error is returned otherwise.

§Examples
let temp_dir = TempDir::new_with_prefix("/tmp/testdir").unwrap();
temp_dir.remove().unwrap();
source

pub fn as_path(&self) -> &Path

Returns the path to the tempdir.

§Examples
let temp_dir = TempDir::new_with_prefix("/tmp/testdir").unwrap();
assert!(temp_dir.as_path().exists());

Trait Implementations§

source§

impl Debug for TempDir

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for TempDir

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.