Struct TempDir

Source
pub struct TempDir {
    pub path: PathBuf,
    /* private fields */
}

Fields§

§path: PathBuf

Path of the temporary directory.

Implementations§

Source§

impl TempDir

Source

pub fn create<P: AsRef<Path>>( &self, filename: P, content: &[u8], ) -> Result<String>

Create a file in the temporary directory and return full path.

Source

pub fn new() -> Result<Self>

Creates a new temporary directory.

This temporary directory and all the files it contains will be removed on drop.

The temporary directory name is constructed by using CARGO_PKG_NAME followed by a dot and random alphanumeric characters.

§Examples
use threecpio::temp_dir::TempDir;

let tempdir = TempDir::new().unwrap();
println!("Temporary directory: {}", tempdir.path.display());
Source

pub fn new_and_set_current_dir() -> Result<Self>

Creates a new temporary directory and changes the current working directory to this directory.

This temporary directory and all the files it contains will be removed on drop. The current working directory will be set back on drop as well.

The temporary directory name is constructed by using CARGO_PKG_NAME followed by a dot and random alphanumeric characters.

Trait Implementations§

Source§

impl Drop for TempDir

Source§

fn drop(&mut self)

Removes the temporary directory and all the files it contains.

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.